enter code here
I am seeing segfaults in a strange part of my code, and after using valgrind, it seemed the problem was the destructor of a parent being called during construction of the child. This is strange, so fired up gdb and indeed, I see constructor of child object being called, constructor of parent being called, and then destructor of parent being called before child constructor has exited. I did a fresh build, saw the same thing.
I assume this is impossible, and something funny is going on, but I have no idea what that might be or how to use gdb to determine what it is. Valgrind just tells me at a later point, when I try to use the parent object that I'm doing an invalid read because the relevant memory was deleted during construction of the child!
It's hard to break out the offending code to give a working example, but I can try to provide any other details that would be helpful. Using gcc 4.7.2.
* Edit * Here's a sketch of the inheritance chain:
class MKTimer: public MKSelfRegistrar<MKTimer>, public MKMakeable1<std::string>, public MKObject, public Timer;
MKObject is the offending parent.
MKTimer(const std::string& timer): Timer(timer) {}
MKObject() { some stuff here that doesn't seem relevant }
* Further Edit *
I'll also mention that there are no explicit calls to delete
and the gdb backtrace shows the call immediately above the parent destructor is the child constructor, so I don't think it's some other piece of code cleaning it up somehow.