RE: [xml] xmlReconciliateNs issues?



Thanks Daniel, putting in the xmlFreeNs fixed it...

-----Original Message-----
From: Daniel Veillard [mailto:veillard redhat com] 
Sent: Sunday, April 18, 2004 11:16 AM
To: Kiely.Daryn
Cc: 'xml gnome org'
Subject: Re: [xml] xmlReconciliateNs issues?


On Fri, Apr 16, 2004 at 10:20:57AM -0700, Kiely.Daryn wrote:
Hi,

I am using xmlReconciliateNs and am experiencing memory leaks.  Here 
is what I think is happening within the method.  The existing 
namespace is being saves in oldNs, and at the end of the method oldNs 
is being freed through xmlFree.  The problem I see with this is the 
internal members of the existing namespace are left hanging.  I don't 
know whether I am using things right, or whether this is a real issue.  
Here is the snippet of code where I am using the method:

   xml_doc = xmlNewDoc ((xmlChar*)"1.0");

   xmlNodePtr new_node = NULL;
   xmlNodePtr root_node = NULL;

   xmlNsPtr ns = xmlNewNs (NULL, (xmlChar*) "namespace_uri", 
(xmlChar*) "prefix");
   root_node = xmlNewDocNode (xml_doc, ns, (xmlChar*) getTagName (),
NULL);
   xmlDocSetRootElement (xml_doc, root_node);
snip..adding more nodes in here...
   xmlReconciliateNs (xml_doc, root_node);

Any help in finding this problem would be greatly appreciated.  Oh, we 
are using libxml 2.6.6.

  I reread the code. xmlReconciliateNs() only create new namespaces in the
target tree, it will not remove the namespaces from the source tree. oldNs
is just an array containing pointers to namespace declarations in the source
document. In no way should said namespaces gathered in oldNs be freed. You
will have to free them when freeing their containg document.

 I don't see any bug in the routine. In the exemple code you provide, 
there is a leak because you do not free the "ns" namespace with the proper
node freeing routine.

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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