cvs: php4(PHP_4_2_0) /ext/domxml php_domxml.c
| From: | Christian Stocker | Date: | Sat, 18 May 2002 10:21:54 +0000 |
| Subject: | cvs: php4(PHP_4_2_0) /ext/domxml php_domxml.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-11982@lists.php.net to get a copy of this message | ||
chregu Sat May 18 06:21:54 2002 EDT
Modified files: (Branch: PHP_4_2_0)
/php4/ext/domxml php_domxml.c
Log:
MFH for memleak patch
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.118.2.8 php4/ext/domxml/php_domxml.c:1.118.2.9
--- php4/ext/domxml/php_domxml.c:1.118.2.8 Fri May 3 11:16:14 2002
+++ php4/ext/domxml/php_domxml.c Sat May 18 06:21:54 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.c,v 1.118.2.8 2002/05/03 15:16:14 chregu Exp $ */
+/* $Id: php_domxml.c,v 1.118.2.9 2002/05/18 10:21:54 chregu Exp $ */
/* TODO
* - Support Notation Nodes
@@ -493,15 +493,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);
+ }
+ }
}
@@ -561,7 +567,6 @@
if (doc) {
node_list_wrapper_dtor(doc->children);
-
node_wrapper_dtor((xmlNodePtr) doc);
xmlFreeDoc(doc);
}
@@ -572,11 +577,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);
}
+
}
@@ -2034,7 +2044,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) {