xerces-c-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Rydgren" <erik.rydg...@mandarinen.se>
Subject Memory leak when parsing DTD.
Date Fri, 02 Feb 2001 14:36:48 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.4208.0">
<TITLE>Memory leak when parsing DTD.</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">I found a memory leak during DTD parse.</FONT>

<BR><FONT SIZE=2 FACE="Arial">It occurs when there is multiple attlist declarations
on the same element in a DTD.</FONT>

<BR><FONT SIZE=2 FACE="Arial">I tracked the problem down to this line (DOMParser.cpp
line 1031 function void DOMParser::endAttList in the IBM-XML4C 3.3.1 release)</FONT></P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fDocumentType-&gt;getElements()-&gt;setNamedItem(elem);</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">The setNamedItem returns the old element if it was
previously defined and it is not handled properly.</FONT>

<BR><FONT SIZE=2 FACE="Arial">I copied the code that handles the same thing from
an other place in the code and the result is:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
EntityImpl *previousElem = (EntityImpl *)</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT
SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fDocumentType-&gt;entities-&gt;setNamedItem( elem ); </FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//&nbsp; If this new entity node is replacing an entity node that was already</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//&nbsp;&nbsp;&nbsp; in the entities named node map (happens if documents redefine
the</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//&nbsp;&nbsp;&nbsp; predefined entited such as lt), we need to delete the original</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//&nbsp;&nbsp;&nbsp; entitiy node, assuming no-one else was referencing it.</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (previousElem != 0 &amp;&amp; previousElem-&gt;nodeRefCount == 0)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
NodeImpl::deleteIf(previousElem);</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I made the change in my version and it works like
a charm.</FONT>

<BR><FONT SIZE=2 FACE="Arial">Hope it contributes.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Best regards</FONT>

<BR><FONT SIZE=2 FACE="Arial">Erik Rydgren</FONT>

<BR><FONT SIZE=2 FACE="Arial">Mandarinen systems AB, Sweden</FONT>
</P>

</BODY>
</HTML>

Mime
View raw message