[libxml-devel] XmlNode Doc is not bound! (ruby_xml_node.c:58) on 0.9.7
Charlie Savage
cfis at savagexi.com
Tue Jan 13 02:15:40 EST 2009
Hi Tor,
> I have created a ticket here:
>
> http://rubyforge.org/tracker/index.php?func=detail&aid=23540&group_id=494&atid=1973
Tel,
Interesting bug, great bug report.
So here is what's happening:
1. Call parser.parse
2. libxml creates a document
3. libxml starts creating nodes
4. Error occurs, libxml creates an error object, with a node pointer
5. The bindings wrap the node as XML::Node, return it to Ruby
6. Exception handler in Ruby is called
7. libxml then frees the document
8. The XML::Node instance sees that its document was never wrapped by
Ruby and calls rb_bug.
It does this because the memory model is based on documents freeing
their nodes. If a document isn't returned to Ruby, then its not under
the control of the garbage collector, and will sooner or later be freed
by libxml itself. That means that any returned wrapper nodes will
sooner or later become invalid causing a segmentation fault. Thus the
check.
In theory the bug should always happen, but doesn't, because the node's
mark method and free method aren't called in simple tests cases. But
they are in yours, due to the reraising of the error object.
Anyway, having the node around is useful to figure out what went wrong.
On the other hand, keeping around the original node is too dangerous
because you could end up with segmentation faults.
So I think the best solution, and the one I implemented, is to return a
copy of the node of interest. So you'll get its namespaces, attributes
and content (but not its parent or children). Copied nodes don't belong
to documents, so there is no danger of libxml freeing the underlying
node object. Nor will a memory leak happen, because once the node goes
error object gets freed by ruby, the node object will be also.
Charlie
>
> best regards,
> Tor Erik
> _______________________________________________
> libxml-devel mailing list
> libxml-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/libxml-devel
--
Charlie Savage
http://cfis.savagexi.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://rubyforge.org/pipermail/libxml-devel/attachments/20090113/6f0f8b9e/attachment.bin>
More information about the libxml-devel
mailing list