[xml] heap neutrality while outputting c14n



Hello , 

I am trying to output c14n bytes of a specific node in my tree. 
For this purpose I have written a general purpose function that will generate C14n bytes by providing a xmlChar** ptr and the xmlNodePtr for which I need the c14n outpput . 

Issue : I would expect that after calling this function and after calling xmlFree() , heap consumption should return to the same value . 

I find that for a a node that contains  around 538 bytes I am losing around 2K bytes worth of heap memory 

eg Usage : 

OutsideFunction(xmlNodePtr pTopNode)
{
   ..
   xmlNodePtr pSubNode = < Some intermediate node unde pTopNode>
   xmlChar **c14data = NULL ; 

-----> Heap logging pt 1 
   if(ConvertXMLTreeToC14Bytes(pSubNode , c14data)>0)
 {
     // Do something 
    xmlFree(c14data);
------> Heap logging pt2 
 }
}

// generate c14n bytes
// output is ppBuffer 
/ user needs to call xmlFree after call to this function to free ppBuffer 
int ConvertXMLTreeToC14Bytes(xmlNodePtr pNode , xmlChar **ppBuffer )
{
if(pNode == NULL || ppBuffer == NULL)
return -1 ; 
int bytesWritten = 0; 
xmlDocPtr pDoc = NULL ; 
xmlDocPtr newDoc = NULL ; 
// if our parent is the doc node then this is top of tree 
if(pNode->doc->children == pNode)
{
pDoc = pNode->doc ; 
}
else
{
// This is a node other than the topmost node
// we create a new document with this node as the root
// create a new Doc 
newDoc = xmlNewDoc((const xmlChar *)"1.0");
if(newDoc == NULL)
return -1 ; 
// copy our node contents to a node under the new doc (newDoc)
// Create a copy of the node 
xmlNodePtr newNode = xmlDocCopyNodeList(newDoc , pNode ); 
if(newNode == NULL)
{
xmlFreeDoc(newDoc);
return -1; 
}
// Add a new node as top of tree for this new doc ! 
//xmlDocSetRootElement(newDoc , newNode);
pDoc = newDoc ; 
}
// now create canonical form 
// doc , All nodes ( NULL) , Exclusive canonicalization , no inclusive namespaces , NO comments in the result , ptr to client buffer ptr 
bytesWritten = xmlC14NDocDumpMemory(pDoc , NULL , 1, NULL, 0, ppBuffer);
if(newDoc)
{
xmlFreeDoc(newDoc) ; 
newDoc = NULL ; 
}
pDoc = NULL ;
return bytesWritten ;
}


Am I missing something here ? Any reason why I would be leaking some heap  ? 


Thanks 





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