From ff19a381c2c418c68237834b020ce853affa8e34 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 16 Sep 2007 16:58:03 +0000 Subject: Fix bug in dom_node_destroy -- Document nodes have no owner, so attempting to ref/unref it is stupid svn path=/trunk/dom/; revision=3538 --- src/core/node.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/core/node.c b/src/core/node.c index 7561c32..26748c4 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -5,6 +5,8 @@ * Copyright 2007 John-Mark Bell */ +#include + #include #include @@ -41,10 +43,15 @@ void dom_node_destroy(struct dom_node *node) /* This function simply acts as a central despatcher * for type-specific destructors. */ - /* Claim a reference upon the owning document during destruction - * to ensure that the document doesn't get destroyed before its - * contents. */ - dom_node_ref((struct dom_node *) owner); + assert(owner != NULL || + (owner == NULL && node->type == DOM_DOCUMENT_NODE)); + + if (owner != NULL) { + /* Claim a reference upon the owning document during + * destruction to ensure that the document doesn't get + * destroyed before its contents. */ + dom_node_ref((struct dom_node *) owner); + } switch (node->type) { case DOM_ELEMENT_NODE: @@ -89,10 +96,13 @@ void dom_node_destroy(struct dom_node *node) break; } - /* Release the reference we claimed on the document. If this is - * the last reference held on the document and the list of nodes - * pending deletion is empty, then the document will be destroyed. */ - dom_node_unref((struct dom_node *) owner); + if (owner != NULL) { + /* Release the reference we claimed on the document. If this + * is the last reference held on the document and the list + * of nodes pending deletion is empty, then the document will + * be destroyed. */ + dom_node_unref((struct dom_node *) owner); + } } /** -- cgit v1.2.3