Re: [xml] segfault after xmlGetProp



LibXML uses it's own memory allocation functions xmlMalloc/xmlFree.
As the first step I would recommend to replace
   free(temp);
with
   xmlFree(temp);
If this will not solve your problem then you should probably try to run
your program using valgrind (http://developer.kde.org/~sewardj/)
to spot the memory corruption place.

Aleksey Sanin.

Simon Geard wrote:

Ok, I'm fairly new to this, having just been playing around with libxml2
in my spare time, using it to try reading a structure for a 3d model
(since I'm also playing with OpenGl in my spare time).

Basically, I've written the following function to retrieve the integer
value of an attribute:

int getIntProp( xmlNodePtr node, char *prop_name ){
 xmlChar *temp;
 int value;

 temp = xmlGetProp( node, (xmlChar*)prop_name );
 value = (int)strtol( (char*)temp, NULL, 10 );
 free(temp);

 return value;
}

According to the libxml documentation, it's up to the caller to free the
memory returned by xmlGetProp. However, sometimes (not every time), I
get a segmentation fault on the call to free().

All the code prior to that is fine - running it through gdb, I find that
'temp' contains the expected value as a string, and that 'value'
contains it as an integer.

The segfault does occur predicatably at the same point in the file I'm
parsing, but the above function has already been called several times
before the segfault occurs.

Ideas appreciated.

Simon.
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]