Bugs item #20117, was opened at 2008-05-13 13:48
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1971&aid=20117&group_id=494

Category: memory
Group: v0.5
Status: Open
Resolution: None
Priority: 3
Submitted By: Gabriel Ebner (gebner)
Assigned to: Nobody (None)
Summary: Segfault when using XML::Reader.expand

Initial Comment:
The following program segfaults under libxml-ruby 0.5.4 (gem) and ruby 1.8.6 
(debian sid / amd64):


require 'rubygems'
require 'xml/libxml'

reader = XML::Reader.new '<a><b/></a>'

2.times do reader.read end
reader.expand if reader.name == 'b'


(gdb) run bug.rb 
Starting program: /usr/bin/ruby bug.rb
[Thread debugging using libthread_db enabled]
[New Thread 0x7f81f824b6e0 (LWP 1298)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f81f824b6e0 (LWP 1298)]
classname (klass=257) at variable.c:150
150     variable.c: No such file or directory.
        in variable.c
(gdb) bt
#0  classname (klass=257) at variable.c:150
#1  0x00007f81f7e0094d in rb_class_path (klass=257) at variable.c:190
#2  0x00007f81f7e00a99 in rb_class2name (klass=257) at variable.c:301
#3  0x00007f81f7d8a13a in rb_check_type (x=257, t=34) at error.c:276
#4  0x00007f81f69f59b8 in ruby_xml_node_deregisterNode (node=0x24f6ba0) at 
ruby_xml_node.c:2264
#5  0x00007f81f676fe3a in xmlTextReaderFreeDoc (reader=0x2510ee0, 
cur=0x24f6ba0) at xmlreader.c:482
#6  0x00007f81f677046d in xmlFreeTextReader__internal_alias (reader=0x2510ee0) 
at xmlreader.c:2195
#7  0x00007f81f7daac81 in rb_gc_call_finalizer_at_exit () at gc.c:1928
#8  0x00007f81f7d90293 in ruby_finalize_1 () at eval.c:1553
#9  0x00007f81f7d98e51 in ruby_cleanup (ex=0) at eval.c:1590
#10 0x00007f81f7d98f69 in ruby_stop (ex=257) at eval.c:1645
#11 0x00007f81f7da46ff in ruby_run () at eval.c:1666
#12 0x0000000000400883 in main (argc=2, argv=0x7fff002691e8, envp=<value 
optimized out>) at main.c:48
(gdb) 


----------------------------------------------------------------------

>Comment By: Gabriel Ebner (gebner)
Date: 2008-05-13 14:11

Message:
I think I have found the problem.  The xmlTextReader usually
deletes the old node when you call xmlTextReaderRead.  This
is why we're getting segfaults when freeing the node.

You can prevent this deletion by calling
xmlTextReaderPreserve, but this will still cause double
frees on the document.

But you can prevent this too by calling
xmlTextReaderCurrentDoc, which will incidentially prevent
the document from being freed automatically.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1971&aid=20117&group_id=494
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to