[xml] segfault after xmlGetProp



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.



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