On Fri, 21 Dec 2012 02:08:12 +1300, Rene Gollent <anevilyak@xxxxxxxxx> wrote:
From a quick glance that should work as well and is IMHO much easier to understand:Your quick glance is incorrect. _RegisterCommand() takes over the reference, ergo your code below results in decrementing the reference count 4 times too many, leading to a double free on exit, hence the dance of a pair of references that was being done prior to the space-based approach.
no, there is only one reference in the calling code and _RegisterCommand creates a CommandEntry holding a ref.
deleting all CommandEntry s would delete the object // CliDumpMemoryCommandBReference<CliCommand> dumpCommandReference(new(std::nothrow) CliDumpMemoryCommand, true);
if (!_RegisterCommand("db", dumpCommandReference) || !_RegisterCommand("db", dumpCommandReference) || !_RegisterCommand("dw", dumpCommandReference) || !_RegisterCommand("dl", dumpCommandReference) || !_RegisterCommand("string", dumpCommandReference)) return B_NO_MEMORY; // next command ... Cheers, Clemens