On Sun, Mar 13, 2011 at 12:51:26AM +0300, Nikolay Sivov wrote:
> Hi.
> 
> It seems to me that xmlAddChild behaviour is kinda unexpected when
> you try to add a node that is altready linked to another document
> (or node of another type). If you don't xmlUnlinkNode before add
> call this results in node being referenced by both documents, so on
> free is will fail (libc crash for me).
> 
> It's fine of course to always do xmlUnlinkNode no matter what but
> what bothers me is that xmlAddChild has xmlSetTreeDoc() inside
> that's called if new parent document doesn't match new child's doc.
> So references are fixed for new node only with xmlSetTreeDoc but not
> for old document it seems.
> 
> Does it sound reasonable to add xmlUnlinkNode in xmlAddChild or I
> should always unlink manually?

I would suggest to unlink. The problem of the document reference
is that it's not only related to the normal parent/children relations
but for example the element subtree may use the source document
dictionary, or namespaces coming from the source. In general
pruning/grafting set of nodes from one document to another is a
complex operation, and I would be as cautious as possible.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
[email protected]  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to