[xml] xmlDOMWrapCloneNode problem
- From: George Georgiev <george georgiev sf gmail com>
- To: xml gnome org
- Subject: [xml] xmlDOMWrapCloneNode problem
- Date: Wed, 1 Aug 2012 21:19:29 -0700
Hi,
I have a problem with xmlDOMWrapCloneNode method. The following is an
isolation test that exposes the issue.
The problem seems to be that when the mathFont is cloned the
newChildNode reference a namespace that is owned from pDoc. If pDoc is
freed when the doc2 is still in use the result is crash.
Is this is a bug or I just do something wrong?
Thanks,
George
static void dump(const xmlDocPtr pDoc, std::string& xmlContent)
{
xmlChar* outBuf;
int outSize;
xmlDocDumpFormatMemory(pDoc, &outBuf, &outSize, TRUE);
xmlContent = std::string((const char *) outBuf);
xmlFree(outBuf);
}
TEST(XmlElementTests, cloneElement2)
{
std::string str =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
"<w:settings xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\"
xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">"
"<m:mathPr>"
"<m:mathFont m:val=\"Cambria Math\"/>"
"</m:mathPr>"
"</w:settings>";
xmlParserCtxtPtr context = xmlNewParserCtxt();
ASSERT_TRUE(context != NULL);
xmlDocPtr pDoc = xmlCtxtReadMemory(context, str.c_str(),
(int)str.size(), "dummy1.xml", NULL, 0);
xmlFreeParserCtxt(context);
XmlNodeRPtr root1 = xmlDocGetRootElement(pDoc);
{
xmlDocPtr doc2 = xmlNewDoc(BAD_CAST "1.0");
doc2->standalone = XmlDoc::standalone_yes;
xml::XmlNodeRPtr root = xmlNewDocNode(doc2, NULL, BAD_CAST
"settings", NULL);
ASSERT_TRUE(root != NULL);
xmlDocSetRootElement(doc2, root);
xml::XmlNamespaceRPtr ns = xmlNewNs(root, BAD_CAST
"http://schemas.openxmlformats.org/wordprocessingml/2006/main",
BAD_CAST "w");
ASSERT_TRUE(ns != NULL);
xmlSetNs(root, ns);
xml::XmlNamespaceRPtr mns = xmlNewNs(root, BAD_CAST
"http://schemas.openxmlformats.org/officeDocument/2006/math", BAD_CAST
"m");
ASSERT_TRUE(mns != NULL);
xml::XmlNodeRPtr mathPr = xmlNewDocNode(doc2, mns, BAD_CAST
"mathPr", NULL);
XmlNodeRPtr mathFont = root1->children->children;
//XmlElement::cloneElement(mathFont, mathPr);
XmlNodeRPtr newChildNode;
xmlDOMWrapCloneNode(NULL, // xmlDOMWrapCtxtPtr - optional
mathFont->doc, // sourceDoc (must not be NULL)
mathFont, // node to clone
&newChildNode, // destNode
mathPr->doc, // destDoc
mathPr, // destParent
TRUE, // deep = clone children
0 // options (ATTRIBUTE_UNUSED)
);
xmlAddChild(mathPr, newChildNode);
xmlAddChild(root, mathPr);
xmlFreeDoc(pDoc);
std::string outStr;
dump(doc2, outStr);
xmlFreeDoc(doc2);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]