From 83eff3f08b8a42d89a6eae8ffb7a373016108d76 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 10 Jul 2007 23:25:18 +0000 Subject: Add NamedNodeMap. Minor fix for NodeList unref function; ensure it unrefs the owner document after it has finished using it. svn path=/trunk/dom/; revision=3395 --- src/core/nodelist.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/core/nodelist.c') diff --git a/src/core/nodelist.c b/src/core/nodelist.c index 1fff561..b37b84e 100644 --- a/src/core/nodelist.c +++ b/src/core/nodelist.c @@ -62,7 +62,7 @@ struct dom_nodelist { * will match the children of ::root. * * The returned list will already be referenced, so the client need not - * do so explicitly. The client should unref the list once finished with it. + * do so explicitly. The client must unref the list once finished with it. */ dom_exception dom_nodelist_create(struct dom_document *doc, struct dom_node *root, struct dom_string *tagname, @@ -124,6 +124,8 @@ void dom_nodelist_ref(struct dom_nodelist *list) void dom_nodelist_unref(struct dom_nodelist *list) { if (--list->refcnt == 0) { + struct dom_node *owner = (struct dom_node *) list->owner; + switch (list->type) { case DOM_NODELIST_CHILDREN: /* Nothing to do */ @@ -139,13 +141,16 @@ void dom_nodelist_unref(struct dom_nodelist *list) dom_node_unref(list->root); - dom_node_unref((struct dom_node *) list->owner); - /* Remove list from document */ dom_document_remove_nodelist(list->owner, list); - /* And destroy the list object */ + /* Destroy the list object */ dom_document_alloc(list->owner, list, 0); + + /* And release our reference on the owning document + * This must be last as, otherwise, it's possible that + * the document is destroyed before we are */ + dom_node_unref(owner); } } -- cgit v1.2.3