Bit of defensive programming and clean up code comments.
@@ -82,10 +82,13 @@ xmlNodePtr rxml_node_root(xmlNodePtr xnode)
void rxml_node_mark(xmlNodePtr xnode)
{
if (xnode->doc)
+ {
+ if (xnode->doc->_private)
{
VALUE doc = (VALUE)xnode->doc->_private;
rb_gc_mark(doc);
}
+ }
else if (xnode->parent)
{
xmlNodePtr root = rxml_node_root(xnode);
@@ -120,8 +123,7 @@ VALUE rxml_node_wrap(xmlNodePtr xnode)
static VALUE rxml_node_alloc(VALUE klass)
{
- /* Ruby is responsible for freeing this node not libxml but don't set
- up mark and free yet until we assign the node. */
+ // This node was created from Ruby so we are responsible for freeing it not libxml
return Data_Wrap_Struct(klass, rxml_node_mark, rxml_node_free, NULL);
}
