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 17:02:30 UTC

More memory leak fixes to nightly build 2001-06-11

Here are the fixes to the other memory leaks I found. All of them is the
result of the use of pointer to pointers construct which got the coder to
shoot himself in the foot.
To clean up such constructs, deallocs in two levels is always required. A
simple 'delete [] ptr2ptr;' is not enough.
But all of you already know that and these bugs are probably cut'n'paste
related :)

Erik Rydgren
Mandarinen systems AB
Sweden

----------------------------------------------------------------------------
-------------------------
ElemStack::~ElemStack()
{
    //
    //  Start working from the bottom of the stack and clear it out as we
    //  go up. Once we hit an uninitialized one, we can break out.
    //
    for (unsigned int stackInd = 0; stackInd < fStackCapacity; stackInd++)
    {
        // If this entry has been set, then lets clean it up
        if (!fStack[stackInd])
            break;

        // Delete the row for this entry, then delete the row structure
>> BEGIN FIX
        for (unsigned int childIndex = 0; childIndex <
fStack[stackInd]->fChildCount; ++childIndex)
          delete fStack[stackInd]->fChildren[childIndex];
>> END FIX
        delete [] fStack[stackInd]->fChildren;
        delete [] fStack[stackInd]->fMap;
        delete fStack[stackInd];
    }

    // Delete the stack array itself now
    delete [] fStack;
}
----------------------------------------------------------------------------
-------------------------
DFAContentModel::~DFAContentModel()
{
    //
    //  Clean up all the stuff that is not just temporary representation
    //  data that was cleaned up after building the DFA.
    //
    delete [] fFinalStateFlags;

    unsigned index;
    for (index = 0; index < fTransTableSize; index++)
        delete [] fTransTable[index];
    delete [] fTransTable;


>> BEGIN FIX
    for (index = 0; index < fLeafCount; index++)
      delete fElemMap[index];
>> END FIX

    delete [] fElemMap;
    delete [] fElemMapType;
    delete [] fLeafListType;
}
----------------------------------------------------------------------------
-------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: More memory leak fixes to nightly build 2001-06-11

Posted by Tinny Ng <tn...@ca.ibm.com>.
Good catch.  Thanks a lot Erik and David.  We will make sure "all" these are
fixed before we release Xerces 1.5.  Thanks!

Tinny

Erik Rydgren wrote:

> Here are the fixes to the other memory leaks I found. All of them is the
> result of the use of pointer to pointers construct which got the coder to
> shoot himself in the foot.
> To clean up such constructs, deallocs in two levels is always required. A
> simple 'delete [] ptr2ptr;' is not enough.
> But all of you already know that and these bugs are probably cut'n'paste
> related :)
>
> Erik Rydgren
> Mandarinen systems AB
> Sweden
>
> ----------------------------------------------------------------------------
> -------------------------
> ElemStack::~ElemStack()
> {
>     //
>     //  Start working from the bottom of the stack and clear it out as we
>     //  go up. Once we hit an uninitialized one, we can break out.
>     //
>     for (unsigned int stackInd = 0; stackInd < fStackCapacity; stackInd++)
>     {
>         // If this entry has been set, then lets clean it up
>         if (!fStack[stackInd])
>             break;
>
>         // Delete the row for this entry, then delete the row structure
> >> BEGIN FIX
>         for (unsigned int childIndex = 0; childIndex <
> fStack[stackInd]->fChildCount; ++childIndex)
>           delete fStack[stackInd]->fChildren[childIndex];
> >> END FIX
>         delete [] fStack[stackInd]->fChildren;
>         delete [] fStack[stackInd]->fMap;
>         delete fStack[stackInd];
>     }
>
>     // Delete the stack array itself now
>     delete [] fStack;
> }
> ----------------------------------------------------------------------------
> -------------------------
> DFAContentModel::~DFAContentModel()
> {
>     //
>     //  Clean up all the stuff that is not just temporary representation
>     //  data that was cleaned up after building the DFA.
>     //
>     delete [] fFinalStateFlags;
>
>     unsigned index;
>     for (index = 0; index < fTransTableSize; index++)
>         delete [] fTransTable[index];
>     delete [] fTransTable;
>
> >> BEGIN FIX
>     for (index = 0; index < fLeafCount; index++)
>       delete fElemMap[index];
> >> END FIX
>
>     delete [] fElemMap;
>     delete [] fElemMapType;
>     delete [] fLeafListType;
> }
> ----------------------------------------------------------------------------
> -------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org