From 967380654ba87462dfb2faeeefbb3ea481fe05a2 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 21 Jul 2012 20:16:26 +0100 Subject: HTMLDocument: If finalise is hung, don't free us underneath ourselves --- src/html/html_document.c | 24 ++++++++++++++---------- src/html/html_document.h | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src/html') diff --git a/src/html/html_document.c b/src/html/html_document.c index ddb8196..7644fde 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -116,15 +116,20 @@ out: } /* Finalise a HTMLDocument */ -void _dom_html_document_finalise(dom_html_document *doc) +bool _dom_html_document_finalise(dom_html_document *doc) { int sidx; - dom_string_unref(doc->cookie); - dom_string_unref(doc->url); - dom_string_unref(doc->domain); - dom_string_unref(doc->referrer); - dom_string_unref(doc->title); + if (doc->cookie != NULL) + dom_string_unref(doc->cookie); + if (doc->url != NULL) + dom_string_unref(doc->url); + if (doc->domain != NULL) + dom_string_unref(doc->domain); + if (doc->referrer != NULL) + dom_string_unref(doc->referrer); + if (doc->title != NULL) + dom_string_unref(doc->title); if (doc->memoised != NULL) { for(sidx = 0; sidx < hds_COUNT; ++sidx) { @@ -136,7 +141,7 @@ void _dom_html_document_finalise(dom_html_document *doc) doc->memoised = NULL; } - _dom_document_finalise(&doc->base); + return _dom_document_finalise(&doc->base); } /* Destroy a HTMLDocument */ @@ -144,9 +149,8 @@ void _dom_html_document_destroy(dom_node_internal *node) { dom_html_document *doc = (dom_html_document *) node; - _dom_html_document_finalise(doc); - - free(doc); + if (_dom_html_document_finalise(doc) == true) + free(doc); } dom_exception _dom_html_document_copy(dom_node_internal *old, diff --git a/src/html/html_document.h b/src/html/html_document.h index fbe7155..bb1a0d2 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -38,7 +38,7 @@ dom_exception _dom_html_document_create( dom_exception _dom_html_document_initialise(dom_html_document *doc, dom_events_default_action_fetcher daf); /* Finalise a HTMLDocument */ -void _dom_html_document_finalise(dom_html_document *doc); +bool _dom_html_document_finalise(dom_html_document *doc); void _dom_html_document_destroy(dom_node_internal *node); dom_exception _dom_html_document_copy(dom_node_internal *old, -- cgit v1.2.3