cvs: php4 /ext/domxml php_domxml.c

From: Date: Sat, 18 May 2002 09:35:29 +0000
Subject: cvs: php4 /ext/domxml php_domxml.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11980@lists.php.net to get a copy of this message
chregu Sat May 18 05:35:29 2002 EDT Modified files: /php4/ext/domxml php_domxml.c Log: This should fix a big bad memory leak in freeing the nodes at script end. Index: php4/ext/domxml/php_domxml.c diff -u php4/ext/domxml/php_domxml.c:1.151 php4/ext/domxml/php_domxml.c:1.152 --- php4/ext/domxml/php_domxml.c:1.151 Thu May 16 17:59:24 2002 +++ php4/ext/domxml/php_domxml.c Sat May 18 05:35:28 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_domxml.c,v 1.151 2002/05/16 21:59:24 chregu Exp $ */ +/* $Id: php_domxml.c,v 1.152 2002/05/18 09:35:28 chregu Exp $ */ /* TODO * - Support Notation Nodes @@ -499,15 +499,21 @@ static inline void node_wrapper_dtor(xmlNodePtr node) { zval *wrapper; - + int refcount = 0; /* FIXME: type check probably unnecessary here? */ if (!node || Z_TYPE_P(node) == XML_DTD_NODE) return; wrapper = dom_object_get_data(node); - - if (wrapper) + + if (wrapper != NULL) { + refcount = wrapper->refcount; zval_ptr_dtor(&wrapper); + /*only set it to null, if refcount was 1 before, otherwise it has still needed references */ + if (refcount == 1) { + dom_object_set_data(node, NULL); + } + } } @@ -567,7 +573,6 @@ if (doc) { node_list_wrapper_dtor(doc->children); - node_wrapper_dtor((xmlNodePtr) doc); xmlFreeDoc(doc); } @@ -578,11 +583,16 @@ { xmlNodePtr node = (xmlNodePtr) rsrc->ptr; - if (node) { - zval *wrapper = dom_object_get_data(node); - if (wrapper) - zval_ptr_dtor(&wrapper); + /* if node has no parent, it will not be freed by php_free_xml_doc, so do it here + and for all children as well. */ + if (node->parent == NULL) { + node_list_wrapper_dtor(node->children); + node_wrapper_dtor(node); + xmlFreeNode(node); + } else { + node_wrapper_dtor(node); } + } @@ -2040,7 +2050,7 @@ * Uwe: must have been a temporary problem. It works for me with both * xmlAddChildList and xmlAddChild */ -// child = xmlAddSibling(nodep, new_child); + child = xmlAddChild(nodep, new_child); if (NULL == child) {

« previous php.cvs (#11980) next »