{C++ etc.}

Latest Posts
Home | C++ Posts | Linux Posts | Programming Posts | Issue Tracking Posts

Sunday, September 06, 2009

Remove Stray Code Lines Before a Code Review

One of the modules that I'm in charge of, had an object which set a bool called b_Delete inside the destructor. While working on a new class which would handle a collection of these objects, I used:
list_A.erase(pX); if (! pX->b_Delete) // Already deleted { delete pX; } This was meant to crash if some other class removed the object in an asynchronous callback. After I have removed all the unwanted deletes else where I could remove the check. Unfortunately, the code remained as is. Right now I'm suffering the consequences. Some of my colleagues who saw this think that I'm not aware that you can't refer to objects inside a deleted object. The code works because I've already removed all of the unwanted delete calls on pX. Note to self: Go through each new code line before a code review

No comments: