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 Nick Chiang <nc...@SS8.com> on 2001/08/16 21:54:33 UTC

memory leaks in Xerces-C++ 1.5.0 version

Hi,

I found two places may have memory leak problem.

	First, in src/validators/common/DFAContentModel.cpp Line 464
function DFAContentModel::buildDFA().

	statement:
	QName* qname = new QName(XMLUni::fgZeroLenString,
XMLUni::fgZeroLenString, XMLContentModel::gEOCFakeId);

	This needs to be freed after the next statement (CMLeaf* nodeEOC =
new CMLeaf(qname);).

	Original Source Code:

	QName* qname = new QName(XMLUni::fgZeroLenString,
XMLUni::fgZeroLenString, XMLContentModel::gEOCFakeId);
            CMLeaf* nodeEOC = new CMLeaf(qname);

	To fix the memory leak:

	QName* qname = new QName(XMLUni::fgZeroLenString,
XMLUni::fgZeroLenString, XMLContentModel::gEOCFakeId);
            CMLeaf* nodeEOC = new CMLeaf(qname);
	delete qname;

	Second, in src/validators/common/DFAContentModel.cpp Line 837.
fHeadNode has to be deleted, since delete 'fLeafList' only remove the leaves
in the tree. The other node such as CMAny, CMBinaryOp and CMUnaryOp won't be
freed. In order to correct this problem there are some codes need to be
change.

	Line: 836 Orig Code DFAContentModel.cpp 

	//delete fHeadNode;
            fHeadNode = 0;

	New Code

	delete fHeadNode;
            //fHeadNode = 0;

	Line: 1046 Orig Code DFAContentModel.cpp

	fLeafList[newIndex] = (CMLeaf*)nodeCur;

	New Code

	fLeafList[newIndex] = new CMLeaf(((CMLeaf*)nodeCur)->getElement(),
	
((CMLeaf*)nodeCur)->getPosition());


Regards,

Nick Chiang

PS: If you plan to fix the problem in future release, would you mind to let
me know the release number. Thanks.

                                                                

Re: memory leaks in Xerces-C++ 1.5.0 version

Posted by Murray Cumming <Mu...@BetaResearch.de>.
I believe that Xerces-C++ 1.5.1 fixed some memory leaks. Anyway, it is
generally a good idea to check the latest version before reporting a
bug.

> Nick Chiang wrote:
> 
> Hi,
> 
> I found two places may have memory leak problem.
> 
>         First, in src/validators/common/DFAContentModel.cpp Line 464
> function DFAContentModel::buildDFA().
> 
>         statement:
>         QName* qname = new QName(XMLUni::fgZeroLenString,
> XMLUni::fgZeroLenString, XMLContentModel::gEOCFakeId);
> 
>         This needs to be freed after the next statement (CMLeaf*
> nodeEOC = new CMLeaf(qname);).
> 
>         Original Source Code:
> 
>         QName* qname = new QName(XMLUni::fgZeroLenString,
> XMLUni::fgZeroLenString, XMLContentModel::gEOCFakeId);
>             CMLeaf* nodeEOC = new CMLeaf(qname);
> 
>         To fix the memory leak:
> 
>         QName* qname = new QName(XMLUni::fgZeroLenString,
> XMLUni::fgZeroLenString, XMLContentModel::gEOCFakeId);
>             CMLeaf* nodeEOC = new CMLeaf(qname);
>         delete qname;
> 
>         Second, in src/validators/common/DFAContentModel.cpp Line 837.
> fHeadNode has to be deleted, since delete 'fLeafList' only remove the
> leaves in the tree. The other node such as CMAny, CMBinaryOp and
> CMUnaryOp won't be freed. In order to correct this problem there are
> some codes need to be change.
> 
>         Line: 836 Orig Code DFAContentModel.cpp
> 
>         //delete fHeadNode;
>             fHeadNode = 0;
> 
>         New Code
> 
>         delete fHeadNode;
>             //fHeadNode = 0;
> 
>         Line: 1046 Orig Code DFAContentModel.cpp
> 
>         fLeafList[newIndex] = (CMLeaf*)nodeCur;
> 
>         New Code
> 
>         fLeafList[newIndex] = new
> CMLeaf(((CMLeaf*)nodeCur)->getElement(),
> 
> ((CMLeaf*)nodeCur)->getPosition());
> 
> Regards,
> 
> Nick Chiang
> 
> PS: If you plan to fix the problem in future release, would you mind
> to let me know the release number. Thanks.
> 
> 

-- 
Murray Cumming
www.murrayc.com
murrayc@usa.net

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