Crash in memory management

Hi everybody!

If one sets the environment variable MMGT_VERBOSE=1 on a Windows system (together with MMGT_CLEAR=1 and MMGT_OPT=1), then the following program will throw an unhandled exception:

#include
#pragma comment(lib, "TKernel.lib")
int main(int argc, char** argv)
{
Standard::StorageManagerInit();
Standard_Address adr = Standard::Allocate(50000);
Standard::Free(adr);
return 0;
}

I found out that the problem is caused by Standard::MFree and can be solved, if one modifies the lines 541-5 in Standard.cxx

else {
free(aStorage);
if (MMgt_Verbose) AllocUsedSpace -= RoundSize;
}
if (MMgt_Verbose) theNbRefList[RoundSize].myRefCounter--;

into

else {
free(aStorage);
if (MMgt_Verbose) {
AllocUsedSpace -= RoundSize;
theNbRefList[RoundSize].myRefCounter--;
}
}

Kind regards, Kris.

Torsten Sadowski's picture

Hi Kris,

if I understand your code correctly, you just remove

if (MMgt_Verbose) theNbRefList[RoundSize].myRefCounter--;

from execution because you are using mmap to allocate memory. I have exactly the same problem on Mac OS X but I don't yet know what MMgt_Verbose does for me, what Roundsize does at all and how it can be negative. Did you analyze the memory manager and can you throw a light on its working?

Cheers, Torsten