Re: [xml] using xmlDocSetRootElement to move nodes between documents
- From: Daniel Veillard <veillard redhat com>
- To: Martijn Faassen <faassen infrae com>
- Cc: xml gnome org
- Subject: Re: [xml] using xmlDocSetRootElement to move nodes between documents
- Date: Wed, 28 Jul 2004 09:53:52 -0400
On Wed, Jul 28, 2004 at 12:07:28PM +0200, Martijn Faassen wrote:
int main() {
xmlDoc* doc1;
xmlDoc* doc2;
xmlNode* node;
xmlChar* text = "<doc>foo</doc>";
char* url = "http://www.infrae.com";
doc1 = xmlReadDoc(text, url, NULL,
XML_PARSE_NOENT | XML_PARSE_NODICT | XML_PARSE_NONET);
doc2 = xmlReadDoc(text, url, NULL,
XML_PARSE_NOENT | XML_PARSE_NODICT | XML_PARSE_NONET);
node = xmlDocGetRootElement(doc1);
xmlImportNode(doc2, node);
xmlDocSetRootElement(doc2, node);
xmlFreeDoc(doc1);
xmlFreeDoc(doc2);
}
This still gives me valgrind invalid reads when doing the xmlFreeDoc().
==17123== Invalid read of size 4
==17123== at 0x80988B4: xmlDictOwns (dict.c:709)
==17123== by 0x805EA32: xmlFreeNodeList (tree.c:3294)
==17123== by 0x805E9DB: xmlFreeNodeList (tree.c:3284)
==17123== by 0x805C9A6: xmlFreeDoc (tree.c:1117)
in xmlFreeNodeList cur->doc->dict is 0xffffffff with memory debug.
The node document still points to the old doc, which has been freed.
xmlDocSetRootElement() should recursively set the document for the subtree...
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]