You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Erik Rydgren <er...@mandarinen.se> on 2001/06/12 16:49:27 UTC
Naughty memory leak in nightly build 2001-06-11
Hi!
I downloaded the latest nightly build, 1.5 candidate and compiled it into
our project which always reuse the validator. I then got MASSIVE memory
leaking out. I tracked the problem down to the ElemStack::addLevel() method.
It reuses the allocated QName* array (fChildren) without deallocating the
old children but just zeroing the counter. I added code to cleanup the mess
a bit and the memory leak went away.
Regards
Erik Rydgren
Mandarinen systems AB
Sweden
PS: I have found more memory leaks and fixed them in this release. I will
post the fixes shortly.
----------------------------------------------------------------------------
-----
Fixed code
----------------------------------------------------------------------------
-----
unsigned int ElemStack::addLevel()
{
// See if we need to expand the stack
if (fStackTop == fStackCapacity)
expandStack();
// If this element has not been initialized yet, then initialize it
if (!fStack[fStackTop])
{
fStack[fStackTop] = new StackElem;
fStack[fStackTop]->fChildCapacity = 0;
fStack[fStackTop]->fChildren = 0;
fStack[fStackTop]->fMapCapacity = 0;
fStack[fStackTop]->fMap = 0;
}
>> START OF ADDED CODE TO FIX PROBLEM
else {
// Cleanup the old element before reuse
for (unsigned int childIndex = 0; childIndex <
fStack[fStackTop]->fChildCount; ++childIndex)
delete fStack[fStackTop]->fChildren[childIndex];
}
>> END OF ADDED CODE TO FIX PROBLEM
// Set up the new top row
fStack[fStackTop]->fThisElement = 0;
fStack[fStackTop]->fReaderNum = 0xFFFFFFFF;
fStack[fStackTop]->fChildCount = 0;
fStack[fStackTop]->fMapCount = 0;
fStack[fStackTop]->fValidationFlag = false;
fStack[fStackTop]->fCurrentScope = Grammar::TOP_LEVEL_SCOPE;
fStack[fStackTop]->fCurrentGrammar = 0;
// Bump the top of stack
fStackTop++;
return fStackTop-1;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org