【问题标题】:C++, libxslt: Freeing the stylesheet document after freeing the style sheet results in crashC++、libxslt:释放样式表后释放样式表文档会导致崩溃
【发布时间】:2012-09-09 19:15:10
【问题描述】:

我正在使用 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(): invalid pointer: 0x00000000026d8090 *)崩溃。

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

【问题讨论】:

    标签: c++ libxml2 libxslt


    【解决方案1】:

    xsltFreeStylesheet 也释放底层文档之类的东西

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    相关资源
    最近更新 更多