libxml2-Question about xmlCreateFileParserCtxt
I'm confused about the return value. I think the ret is a newly allocated memory, and I need to free it by using xmlFreeParserCtxt. But when I remove xmlFreeParserCtxt, I found there is no error and I'm sure the ret value is not NULL!(I use fsanitize=address to detect)
If the ret value of xmlCreateFileParserCtxt is not NULL, is it possible that it isn't newly allocated?
My code:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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;
}
First, I add the xmlFreeParserCtxt(ctxt);, I'm sure there is no error msg. And then, I delete this line. I compile this code by: gcc ./test.c -g -lxml2 -fsanitize=address.I think I should got error output, but nothing happened. No memleaks!
0 comments:
Post a Comment
Thanks