summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-09-16 16:58:03 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-09-16 16:58:03 +0000
commit2c12bb68586efa3efaa1b2bf331473cba9169296 (patch)
tree648273a61bd1162a3f28c92c51ae60467eb1b26a
parent2200fe7243e1edba7940d44c7f91dac6cb5b9ac5 (diff)
downloadlibdom-2c12bb68586efa3efaa1b2bf331473cba9169296.tar.gz
libdom-2c12bb68586efa3efaa1b2bf331473cba9169296.tar.bz2
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
-rw-r--r--src/core/node.c26
1 files 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 <jmb@netsurf-browser.org>
*/
+#include <assert.h>
+
#include <dom/core/document.h>
#include <dom/core/string.h>
@@ -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);
+ }
}
/**