C ++,libxslt:释放样式表后释放样式表文档会导致崩溃

时间:2012-09-09 19:15:10

标签: c++ libxml2 libxslt

我正在使用libxml2和libxslt从C ++程序进行XML处理。为了使用XSL转换XML文档,我使用以下函数(删除了错误处理):

xmlDocPtr
transformXmlDocument(
    const xmlDocPtr inputDocument,
    const std::string& stylesheetString
    ) {

    exsltRegisterAll();

    // Read the stylesheet document.
    xmlDocPtr stylesheetDocument = xmlReadMemory(
            stylesheetString.c_str(),
            stylesheetString.length(),
            "stylesheet.xsd",
            0, // No encoding set - get it from the file header.
            0  // No further options.
    );

    // Parse the stylesheet
    xsltStylesheetPtr stylesheet = xsltParseStylesheetDoc(stylesheetDocument);

    // Transform the document
    xmlDocPtr result = xsltApplyStylesheet(stylesheet, inputDocument, 0);

    // Free used resources
    xsltFreeStylesheet(stylesheet);
    xsltCleanupGlobals();

    // Here the program crashes
    xmlFreeDoc(stylesheetDocument);

    return result;
}

问题是程序崩溃时出现访问冲突(glibc说:free():无效指针:0x00000000026d8090 * )在最后一行。

我在文档中找不到xsltFreeStylesheet还释放底层文档或其他东西的任何提示,所以这里有什么问题?

1 个答案:

答案 0 :(得分:2)

  

xsltFreeStylesheet还可以释放基础文档或其他内容

The fine manual有一些提示表明这种情况确实有可能发生。