Hi,

 For the attached file if I do Dom parsing, or use Reader Api's to parse
with purify, a memory leak is shown for memory allocated at the following
location in function

xmlNewReference(tree.c)

cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));

The cur node is being allocated for the entities present in the document.
The entities themselves are defined in an external DTD. However the path
given for the DTD is incorrect, so the entity is not resolved. xmlAddChild
is called to add this node (cur) to the tree. However in this function there
is a check to see if the parent is NULL, which happens to be the case. So it
returns NULL without freeing the node (cur), hence the leak. 

I think if we free the node inside the null check for parent it should
prevent the leak, however I am not sure whether this is the right place to
fix the problem. I have attached the patch which fixes the problem.

 

Regards

Ashwin 

 

 

 

 

 

 

<?xml version='1.0' standalone='no'?>

<!DOCTYPE attributes SYSTEM "/invalidsystemid/sa.dtd" [
    <!--
	This one is almost standalone since the values
	are pre-normalized in this document, and the
	defaulted attribute is explicit.
    
	BUT the entity refs are both external and need
	normalization.
    -->
]>

<attributes
    token =	"b"
    notation =	"foo"
    nmtoken =	"this-gets-normalized"
    nmtokens =	"this also gets normalized"
    id =	"&internal;"
    idref =	"&internal;"
    idrefs =	"&internal; &internal; &internal;"
    entity =	"unparsed-1"
    entities =	"unparsed-1 unparsed-2"
    cdata =	"nothing happens to this one!"
    />
*** tree.c      2007-05-28 06:08:52.000000000 -0700
--- memleakfixtree.c    2008-01-24 08:48:51.000000000 -0800
*************** xmlAddChild(xmlNodePtr parent, xmlNodePt
*** 3224,3229 ****
--- 3224,3233 ----
          xmlGenericError(xmlGenericErrorContext,
                "xmlAddChild : parent == NULL\n");
  #endif
+       if (cur != NULL)
+       {
+               xmlFreeNode(cur);
+       }
        return(NULL);
      }
  
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to