Re: [xml] xmlDOMWrapCloneNode problem


I am new to this group. I reported this issue a while ago and I have
no response so far.

Could you please advice, do I need to report it in a different manner
or what? Is there somebody who monitors the group for issues like that
at all or I just need to fix this and any other issue I run into


On Wed, Aug 1, 2012 at 9:19 PM, George Georgiev
<george georgiev sf gmail com> wrote:

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?


static void dump(const xmlDocPtr pDoc, std::string& xmlContent)
    xmlChar* outBuf;
    int      outSize;
    xmlDocDumpFormatMemory(pDoc, &outBuf, &outSize, TRUE);
    xmlContent = std::string((const char *) outBuf);

TEST(XmlElementTests, cloneElement2)
    std::string str =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
"<w:settings xmlns:m=\"\";
        "<m:mathFont m:val=\"Cambria Math\"/>"

    xmlParserCtxtPtr context = xmlNewParserCtxt();
    ASSERT_TRUE(context != NULL);

    xmlDocPtr pDoc = xmlCtxtReadMemory(context, str.c_str(),
(int)str.size(), "dummy1.xml", NULL, 0);


    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
BAD_CAST "w");
        ASSERT_TRUE(ns != NULL);

        xmlSetNs(root, ns);

        xml::XmlNamespaceRPtr mns = xmlNewNs(root, BAD_CAST
        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);

        std::string outStr;
        dump(doc2, outStr);


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