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 document8. 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@rubyforge.org http://rubyforge.org/mailman/listinfo/libxml-devel
-- Charlie Savage http://cfis.savagexi.com
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ libxml-devel mailing list libxml-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/libxml-devel