Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a new document by with a root node cloned from another causes segfault #91

Closed
pdlug opened this issue Jul 2, 2009 · 6 comments

Comments

@pdlug
Copy link

pdlug commented Jul 2, 2009

When trying to create a new document from part of an existing document via #dup a segfault results:

doc = Nokogiri::XML('<title>test</title>')
doc2 = Nokogiri::XML::Document.new
doc2.root = doc.root.dup(1)

@pdlug
Copy link
Author

pdlug commented Jul 2, 2009

Should have noted that this occurs both on Mac OS X (libxml2 2.7.3) and Gentoo Linux (libxml2 2.7.2).

@flavorjones
Copy link
Member

This is more of the node dictionary allocation issue, which occurs when nodes have resources owned by another document. In this case, when the node is dup()ed, it still references dictionary strings owned by the original document. At GC time, things blow up.

@flavorjones
Copy link
Member

Basically, libxml2 does not support moving nodes from one document to another, nor does it support moving dupes of a node to another document. Sigh.

@tenderlove
Copy link
Member

But this shouldn't be that problem, right? I thought we copied the tree on dups?

@flavorjones
Copy link
Member

This is that problem! Really. I think if we copy the document, everything works correctly. But copying a node and jamming it into another doc is definitely going to break libxml.

@tenderlove
Copy link
Member

moving roots around will copy them and gc old roots. closed by 10f5710

flavorjones pushed a commit that referenced this issue Apr 7, 2021
This involves several fixes:
1. Removing the linker flag that causes the error.
2. Adding scripts to simplify and speed up testing, in particular both
   the `--with-libxml2` and `--without-libxml2` are tested in each
   build.
3. Adding a script to create and run a Docker container based on
   stevecheckoway/gentoo-ruby which is based on the official Gentoo
   image but with ruby, libxml2, and bundler installed.
4. A somewhat unrelated change to fix an issue when Nokogiri is built
   with system libraries. In this case, `pkg-config` needs to be
   available which is easiest to provide via the `pkg-config` gem.
   Unfortunately, bundler installs dependencies in alphabetical order
   and this needs to be installed before Nokogiri. To resolve this,
   `scripts/fix-dep-order.gemspec` (which comes alphabetically before
   `nokogiri`) declares a dependency on `pkg-config` thus building it
   first. This is a ridiculous work-around, but I couldn't find an
   alternative.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants