I have a particular class hierarchy that is causing memory to be released twice.
What seems to be the problem is the following section of code:
1 2 3 4 5
|
void FOO::ProcessTable (const TABLE & table)
{ SQLERR sqlerr;
const KEYDEF * prikey;
string temp;
TABLEDEF tabledef (table);
|
An exception is getting thrown several levels deep in TABLEDEF's construction.
I know why the exception is being thrown and how to fix it. That's not the issue. The problem is that the exception handling is unwinding objects on the stack and calling TABLEDEF's destructor, which in turn calls every other destructor in the heirarchy all the way to std::string which is the base class. string's destructor is calling delete which is causing an abend attempting to release memory that is not allocated. I know the underlying string was in fact allocated and correct.
Before I fix the cause of the exception being thrown, I want to find why string memory is apparently getting released twice. I've checked all the constructors in the chain and all are passing objects as const reference to the next level. All the destructors are virtual.
Any suggestions on how to find the cause of the memory being released twice?
I've tried various stratagies in the debugger to no avail, including setting a memory access breakpoint on the underlying string object. Stepping into the throw was no help.
Note: The try/catch logic is one level up from this function.