RE: [xml] xmlTextReaderClose causing segfault



I reported the same problem some time ago, but found that I had a couple ot things wrong with my code (using gdb/valgrind of course).  
 
I had a code sequence like:
 
xmlTextReaderPtr reader;
...
reader = xmlReaderForMemory (buf, size, NULL, NULL, 0);
while (ret == 1) {
    ... 
    ret = xmlTextReaderNext(reader);      // skip subtree ...
    ...
    ret = xmlTextReaderRead(reader); ...
   }
   ....
 
   xmlFreeTextReader(reader);             // THIS USE TO CAUSE A SEG VIOLATION  trying to free reader->ctxt
 
After doing some stack reorganization, in a few (c++) routines, I found the real cause of my problem - over-writing some other variable.  While I don't know your code organization, I would recommend using some tools (gdb, valgrind, etc) to help debug.  There may still be a bug in this area, I am simply not seeing the one I saw anymore; I'm using libxml2.6.5.
 
I've found that these kinds of bugs/features can be very nasty and hard to sort out.  Good luck to you.
 
M. Jones
-----Original Message-----
From: Rob Richards [mailto:rrichards ctindustries net]
Sent: Saturday, April 17, 2004 8:48 AM
To: xml gnome org
Subject: [xml] xmlTextReaderClose causing segfault

I just started playing around with the xmlTextReader stuff so not sure if I am just using this wrong or if this is really a bug (assuming bug). I'm currently using the api calls from 2.5.11 though have also run this under 2.6.8 with the same problem.
 
When calling xmlTextReaderClose and xmlFreeParserCtxt(reader->ctxt) is called, reader->ctxt never gets set to null and is causing a segfault in xmlFreeTextReader when it uses reader->ctxt. Also looks like it would be a problem with the 2.6 api if xmlTextReaderSetup were called after xmlTextReaderClose as well. xmlTextReaderGetRemainder also looks like it has the same problem as xmlTextReaderClose since it also frees the parser context and doesnt set to NULL.
 
If this is a bug is there any workaround that can be used (that would also work under 2.5.11) since there is no access to the xmlTextReader structure manually setting ctxt to NULL after calling xmlTextReaderClose wont work.
 
Thanks,
 
Rob


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