[libxml-devel] [ libxml-Bugs-16214 ] SEGV when add the cloned/copied node

noreply at rubyforge.org noreply at rubyforge.org
Mon Dec 10 10:37:36 EST 2007


Bugs item #16214, was opened at 2007-12-10 10:29
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1971&aid=16214&group_id=494

Category: memory
Group: v0.5
Status: Open
Resolution: None
Priority: 4
Submitted By: Dan Janowski (danj)
Assigned to: Dan Janowski (danj)
Summary: SEGV when add the cloned/copied node

Initial Comment:
Originally appeared on mail list by optyk (2007-11-27).

segv appears when use clone and copy methods,
what's interesting, with clone segv is thrown in div1.child_add(c)
line (see script)
but when use copy I get it in printf root statement, moreover copy
seems to work wrong only for text nodes, when use 't3' div everything
works fine

I get this error on 0.5.2.0, 0.5.2.1 and 0.5.2.2 (latest svn) version

it looks like fix is required in ruby-libxml code,

BTW. it looks also like ruby_xml_node_copy() in ruby_xml_node.c calls
xmlCopyNode() with wrong attributes, it should be 2 for shallow copy
and 1 for deep copy

-------------------- SCRIPT ---------------------
require 'xml/libxml'

str = <<-STR
<html>
   <body>
       <div class="textarea" id="t1"
style="STATIC">werwerwerwerwer                 </div>
       <div class="textarea" id="t2" style="STATIC">
           Quisque et diam dapibus nisi bibendum blandit.
       </div>
       <div class="textarea" id="t3" style="STATIC">
           <p>aaaaaaaaa</p>
       </div>
   </body>
</html>
STR


XML::Parser.default_keep_blanks = false
xp = XML::Parser.new
xp.string = str
doc = xp.parse

xpath = "//div[@id='t1']"
div1 = doc.find(xpath).to_a[0]
printf "xxx div1: #{div1}\n"

xpath = "//div[@id='t2']"
div2 = doc.find(xpath).to_a[0]
printf "xxx div2: #{div2}\n"


div2.each do |child|
   #c = child.clone
   c = child.copy(false)
   div1.child_add(c)
end

printf "xxx root: #{doc.root}\n"


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

>Comment By: Dan Janowski (danj)
Date: 2007-12-10 10:37

Message:
keisuke fukuda submitted a patch for this problem which I have carefully examined. The given patcch fixes the problem by creating an unintended consequence, by always copying text nodes. However, the real cause of the problem is more subtle and has to do with merging of text nodes when the parent node already has an associated text node. Since we cannot have a text node that is mapped into ruby simply disappear, they do always need to be copied. However, a few additional conditions needed to be handled.

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

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1971&aid=16214&group_id=494


More information about the libxml-devel mailing list