Reputation: 19
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 <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;
}
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!
Upvotes: 0
Views: 97