I am still confused because I think that I am using xmlChar * that are
causing the problem. See my code below. Using gdb the error shows up on
the calls to
xmlMemFree(xmlElementName);
xmlMemFree(xpathExpr);
Those 2 strings I am freeing with xmlMemFree come from a xmlStrncatNew and a
xmlStrndup. I was under the impression that these created new strings with
xmlMalloc which I should be able to xmlMemFree... No?
Thanks
----- CODE CAUSING PROBLEM -----
GetElements(xmlNodePtr node, const char * elementName)
{
XmlElementListPtr elements = NULL;
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
int status = 0;
if (node != NULL)
{
/* Create xpath evaluation context */
xpathCtx = xmlXPathNewContext(node->doc);
if (xpathCtx == NULL)
{
fprintf(stderr, "Error: unable to create new XPath context\n");
status = -1;
}
xpathCtx->node = node;
const xmlChar * xPathLocal = (xmlChar *)"./";
xmlChar * xmlElementName = xmlCharStrndup(elementName,
strlen(elementName));
xmlChar * xpathExpr = xmlStrncatNew(xPathLocal, xmlElementName, -1);
/* Evaluate xpath expression */
xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
if (xpathObj == NULL)
{
fprintf(stderr, "Error: unable to evaluate xpath expression
\"%s\"\n",
xpathExpr);
}
/* Print results */
elements = BuildElementList(xpathObj);
/* Cleanup */
xmlMemFree(xmlElementName);
xmlMemFree(xpathExpr);
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
}
return elements;
}
On Thu, Apr 29, 2010 at 9:14 AM, Daniel Veillard <[email protected]>wrote:
> On Wed, Apr 28, 2010 at 11:01:25AM -0400, ecforu wrote:
> > I keep getting the same errors (see below) when I run my c program using
> > libxml2-2.7.3.
>
> means 1/ you're using a libxml2 library build with memory debugging
> 2/ you're doing allocation errors in your program
>
> > xmlMallocBreakpoint reached on block 0
> > Memory tag error occurs :0x35988
> > bye
> > xmlMemFree(359A0) error
> > xmlMallocBreakpoint reached on block 0
>
> run your program under gdb and put a breakpoint in xmlMallocBreakpoint
> to stop the programe at the time teh error is made and debug.
>
> Note that compiling with memory debug means that you will see such an
> error if you allocate with malloc and try to xmlFree() the result or
> try to free() memory allocated by libxml2 (instead of using xmlFree)
> which usually work but not under memory debug which is specifically
> designed to catch libxml2 memeory usage errors.
>
> Daniel
>
> --
> Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
> [email protected] | Rpmfind RPM search engine http://rpmfind.net/
> http://veillard.com/ | virtualization library http://libvirt.org/
>
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml