Re: [xml] xmlReconciliateNs issues?

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

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*)
   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 Veillard      | Red Hat Desktop team
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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