c++heap-corruptiongflags

new object causes corruption on the heap


I've been struggling with a heap corruption problem for a few days. I was first warned by the vs 2005 debugger that I may have corrupted the heap, after deleting an object I had previously new'ed. Doing research on this problem led me to gflags and the page heap setting. After enabling this setting for my particular image, it supposedly pointed me to the line that is actually causing the corruption.

Gflags identified the constructor for the object in question as the culprit. The object derives as follows:

class POPUPS_EXPORT MLUNumber :  public MLUBase
  {
...
  }
class POPUPS_EXPORT MLUBase : public BusinessLogicUnit
  {
...
  }

I can instantiate an MLUNumber in a separate thread, and no heap corruption occurs.

I can instantiate a different class, that also inherits from MLUBase, that does not cause heap corruption.

The access violation raises due to the corruption occurs on the opening brace of the constructor, which appears to be because of the implicit initializing of the object (?).

The base class constructor (MLUBase) successfully finishes.

From digging with the memory window in vs 2005, it appears that there was not enough space allocated for the actual object. My guess is that enough was allocated for the base class only.

The line causing the fault:

BusinessLogicUnit* biz = new MLUNumber();

I'm hoping for either a reason that might cause this, or another troubleshooting step to follow.


Solution

  • Unfortunately, with the information given, it's not possible to definitively diagnose the problem.

    Some things you may want to check: