提问人:icy17 提问时间:7/3/2023 最后编辑:yugricy17 更新时间:10/26/2023 访问量:35
libxml2 - 关于 xmlCreateFileParserCtxt 的问题
libxml2-Question about xmlCreateFileParserCtxt
问:
我对返回值感到困惑。我认为是新分配的内存,我需要使用 .但是当我删除时,我发现没有错误,并且我确定 ret 值不是 NULL!(我用来检测)
如果 的 ret 值不是 ,是否有可能不是新分配的?ret
xmlFreeParserCtxt
xmlFreeParserCtxt
-fsanitize=address
xmlCreateFileParserCtxt
NULL
我的代码:
#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
答: 暂无答案
评论