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?
Nikolay
#include <stdio.h>
#include <libxml/tree.h>
int main(void)
{
xmlDocPtr doc, doc2;
xmlNodePtr elem;
doc = xmlNewDoc(0);
doc2 = xmlNewDoc(0);
elem = xmlNewDocNode(doc, 0, "elemtest", 0);
xmlAddChild((xmlNodePtr)doc, elem);
/* xmlUnlinkNode(elem); */
xmlAddChild((xmlNodePtr)doc2, elem);
printf("free doc %p\n", doc2);
xmlFreeDoc(doc2);
printf("free doc %p\n", doc);
xmlFreeDoc(doc);
}
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml