I was using xmlTextReaderGetAttribute (from xmlsoft.org) successfully before, but the API documentation requires that I deallocate the returned xmlChar*. Now my app crashes on the second (the first passes null) call to free(), shown below:
xmlTextReaderPtr reader = null;
xmlChar *attribVal = null;
//blah...
if (xmlTextReaderAttributeCount(reader) > 0) {
free((attribVal));
attribVal = xmlTextReaderGetAttribute(reader, (const xmlChar*)"super-Attrib");
if (xmlStrcasecmp(attribVal, (const xmlChar*)"monoMega-Attrib") == 0) {
free((attribVal));
my project is in C++ but the libxml2 and all examples from xmlsoft.org use standard C.
Use xmlFree() instead of free() directly:
xmlTextReaderPtr reader = null;
xmlChar *attribVal = null;
//blah...
if (xmlTextReaderAttributeCount(reader) > 0)
{
attribVal = xmlTextReaderGetAttribute(reader, BAD_CAST "super-Attrib");
if (attribVal)
{
...
xmlFree(attribVal);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With