[xml] Memleak in xmlNewReference



 

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

 

 

 

 

 

 

Attachment: not-sa03.xml
Description: Text Data

Attachment: treepatch.txt
Description: Text document



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]