From 618d6c904dd5c7c28d8f2c67e66e7fbcda8d6c8b Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Fri, 25 Jul 2003 17:25:50 +0000 Subject: [PATCH] doctype and namespace fix memory leak fix --- ext/dom/domimplementation.c | 42 ++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/ext/dom/domimplementation.c b/ext/dom/domimplementation.c index 1a9f8a4c92..fccae0b6f3 100644 --- a/ext/dom/domimplementation.c +++ b/ext/dom/domimplementation.c @@ -130,7 +130,7 @@ PHP_FUNCTION(dom_domimplementation_create_document) zval *node = NULL, *rv = NULL; xmlDoc *docp; xmlNode *nodep; - xmlDtdPtr doctype = NULL, dtd = NULL; + xmlDtdPtr doctype = NULL; xmlNsPtr nsptr = NULL; int ret, uri_len = 0, name_len = 0; char *uri, *name; @@ -142,7 +142,7 @@ PHP_FUNCTION(dom_domimplementation_create_document) return; } - if (doctype != NULL) { + if (node != NULL) { DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj); if (doctype->type == XML_DOCUMENT_TYPE_NODE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid DocumentType object"); @@ -192,20 +192,16 @@ PHP_FUNCTION(dom_domimplementation_create_document) xmlFreeURI(uristruct); if (uri_len > 0) { - if (prefix == NULL) { + if ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL) { php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace"); - xmlFree(localname); - RETURN_FALSE; - } else { - if ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL) { - php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC); + if (prefix != NULL) { xmlFree(prefix); - xmlFree(localname); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace"); - RETURN_FALSE; } + xmlFree(localname); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace"); + RETURN_FALSE; } + } if (prefix != NULL) { xmlFree(prefix); @@ -223,24 +219,42 @@ PHP_FUNCTION(dom_domimplementation_create_document) } if (doctype != NULL) { - dtd = xmlCreateIntSubset (docp, doctype->name, - doctype->ExternalID, doctype->SystemID); + docp->intSubset = doctype; + doctype->parent = docp; + doctype->doc = docp; + docp->children = (xmlNodePtr) doctype; + docp->last = (xmlNodePtr) doctype; } if (localname != NULL) { nodep = xmlNewDocNode (docp, nsptr, localname, NULL); if (!nodep) { + if (doctype != NULL) { + docp->intSubset = NULL; + doctype->parent = NULL; + doctype->doc = NULL; + docp->children = NULL; + docp->last = NULL; + } xmlFreeDoc(docp); xmlFree(localname); /* Need some type of error here */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected Error"); RETURN_FALSE; } + + nodep->nsDef = nsptr; + xmlDocSetRootElement(docp, nodep); xmlFree(localname); } DOM_RET_OBJ(rv, (xmlNodePtr) docp, &ret, NULL); + + if (doctype != NULL) { + doctobj->document = ((dom_object *)((node_ptr *)docp->_private)->_private)->document; + increment_document_reference(doctobj, docp TSRMLS_CC); + } } /* }}} end dom_domimplementation_create_document */ -- 2.50.1