[no subject]
----- Original Message -----
From: Jones, Mark A <mailto:jones lucent com> (Mark)
To: 'Rob Richards' <mailto:rrichards ctindustries net> ; xml gnome org <mailto:xml gnome org> ; Jones, Mark
A <mailto:jones lucent com> (Mark)
Sent: Saturday, April 17, 2004 10:47 AM
Subject: 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
------_=_NextPart_001_01C42494.8F46E2E6
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=556274515-17042004><FONT face=Arial color=#0000ff
size=2>Rob,</FONT></SPAN></DIV>
<DIV><SPAN class=556274515-17042004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=556274515-17042004><FONT face=Arial color=#0000ff size=2>As I
noted in my earlier email, there may still be a bug in this area. Even
though my problem "appeared" to be solved, I am still a little perplexed as
to why reader->ctxt would have a very valid value, but yet it
appears as though the block of memory pointed was <FONT color=#ff0000>not</FONT>
allocated (at the point of<FONT color=#ff0000>
free(reader->ctxt).</FONT> I could not find any place where I was
inadvertently freeing reader->ctxt in my code. You may have to
send a </FONT></SPAN></DIV>
<DIV><SPAN class=556274515-17042004><FONT face=Arial color=#0000ff
size=2>bug-reproducible piece of code to the folks who provide the libxml2
package(s). Good luck to you.</FONT></SPAN></DIV>
<DIV><SPAN class=556274515-17042004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=556274515-17042004><FONT face=Arial color=#0000ff size=2>M.
Jones</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Rob Richards
[mailto:rrichards ctindustries net]<BR><B>Sent:</B> Saturday, April 17, 2004
11:40 AM<BR><B>To:</B> Jones, Mark A (Mark); xml gnome org<BR><B>Subject:</B>
Re: [xml] xmlTextReaderClose causing segfault<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2>I have gone through with a debugger and even
tried dumbing it way down. Its only when I try to use xmlTextReaderClose that
the problem happens as that is one of the 2 places (other than
xmlFreeTextReader) where xmlFreeParserCtxt is called. Once I make the call to
xmlTextReaderClose, the final call to xmlFreeTextReader segfaults (actually in
xmlTextReaderFreeDoc) as the first test for the context in xmlFreeTextReader
is:</FONT></DIV>
<DIV><FONT face=Arial size=2>if (reader->ctxt != NULL) { // Here it is not
NULL but has already been freed so it's garabge).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>From what I am seeing is that if
xmlTextReaderClose is called and the context is freed, I cant free the reader
at the end or I end up with a segfault.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>This is a really dumbed down example of the
segfault (segfaults in 2.5.11 as well as 2.6.8):</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>int ret;</FONT></DIV>
<DIV><FONT face=Arial size=2>xmlTextReaderPtr myreader;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>myreader = xmlNewTextReaderFilename(source);
/*source is valid file and does create valid xmlTextReaderPtr */</FONT></DIV>
<DIV><FONT face=Arial size=2>ret = xmlTextReaderClose(myreader); /* Closes
fine */<BR>xmlFreeTextReader(myreader); /* segfaults here as reader->ctxt
is garbage */</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid;
MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=jones lucent com href="mailto:jones lucent com">Jones, Mark A
(Mark)</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=rrichards ctindustries net
href="mailto:rrichards ctindustries net">'Rob Richards'</A> ; <A
title=xml gnome org href="mailto:xml gnome org">xml gnome org</A> ; <A
title=jones lucent com href="mailto:jones lucent com">Jones, Mark A
(Mark)</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, April 17, 2004 10:47
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> RE: [xml] xmlTextReaderClose
causing segfault</DIV>
<DIV><BR></DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff size=2>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).
</FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff size=2>I
had a code sequence like:</FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2>xmlTextReaderPtr reader;
</FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2>...</FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2>reader = xmlReaderForMemory
(buf, size, NULL, NULL, 0);</FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2>while (ret == 1) <SPAN
class=745452914-17042004>{</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004></SPAN><SPAN
class=745452914-17042004> ...
</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004> </SPAN>ret =
xmlTextReaderNext(reader); <SPAN
class=745452914-17042004> // skip subtree
...</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004> ... </SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004> r</SPAN>et =
xmlTextReaderRead(reader); <SPAN
class=745452914-17042004>...</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004> } </SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004> ....</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN class=745452914-17042004><FONT size=2><SPAN
class=745452914-17042004> </SPAN></FONT><FONT size=2><FONT
color=#ff0000>xmlFreeTextReader(reader); <SPAN
class=745452914-17042004>
// THIS USE TO CAUSE A SEG VIOLATION trying to free
reader->ctxt</SPAN></FONT></FONT></DIV></SPAN>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff
size=2>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.</FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff
size=2>I've found that these kinds of bugs/features can be very nasty and
hard to sort out. Good luck to you.</FONT></SPAN></DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=745452914-17042004><FONT face=Arial color=#0000ff size=2>M.
Jones</FONT></SPAN></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------_=_NextPart_001_01C42494.8F46E2E6--
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]