libxml2 - 关于 xmlCreateFileParserCtxt 的问题

libxml2-Question about xmlCreateFileParserCtxt

提问人:icy17 提问时间:7/3/2023 最后编辑:yugricy17 更新时间:10/26/2023 访问量:35

问:

我对返回值感到困惑。我认为是新分配的内存,我需要使用 .但是当我删除时,我发现没有错误,并且我确定 ret 值不是 NULL!(我用来检测) 如果 的 ret 值不是 ,是否有可能不是新分配的?retxmlFreeParserCtxtxmlFreeParserCtxt-fsanitize=addressxmlCreateFileParserCtxtNULL

我的代码:

#include <stdio.h>
#include <libxml/xmlreader.h>
#include <libxml/xmlwriter.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxml/uri.h>
#include <libxml/valid.h>
#include <libxml/xmlsave.h>
#include <libxml/nanoftp.h>
#include <libxml/schemasInternals.h>
#include <libxml/relaxng.h>
#include <libxml/xmlschemas.h>
#include <libxml/dict.h>
#include <libxml/pattern.h>
#include <libxml/hash.h>
#include <libxml/xmlversion.h>

int main() {
    const char* xmlFilePath = "example.xml";

    // Create a parser context for parsing an XML file
    xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(xmlFilePath);
    if (ctxt == NULL) {
        printf("Failed to create parser context for file: %s\n", xmlFilePath);
        return 1;
    }


    // Cleanup
    // xmlFreeParserCtxt(ctxt);

    return 0;
}

首先,我添加 ,我确定没有错误消息。然后,我删除了这一行。我通过以下方式编译此代码: .我想我应该得到错误输出,但什么也没发生。没有记忆!xmlFreeParserCtxt(ctxt);gcc ./test.c -g -lxml2 -fsanitize=address

c libxml2 地址清理器

评论

0赞 273K 7/3/2023
不要使用 C++ 标记 C 代码
0赞 icy17 7/4/2023
@273K我只是编辑标签。不好意思。。。

答: 暂无答案