#14037 [Opn->Bgs]: domxml: Memory leak in xmldocfile function
| From: | kalowsky@php.net | Date: | Sat, 10 Aug 2002 22:44:18 +0000 |
| Subject: | #14037 [Opn->Bgs]: domxml: Memory leak in xmldocfile function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16463@lists.php.net to get a copy of this message | ||
ID: 14037
Updated by: kalowsky@php.net
Reported By: mikep@oeone.com
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 4.0.6
Assigned To: mfischer
New Comment:
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP --
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php
If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
Previous Comments:
------------------------------------------------------------------------
[2001-12-11 17:25:13] mfischer@php.net
De-assigned, makeing it a feature request.
------------------------------------------------------------------------
[2001-11-29 19:05:09] mfischer@php.net
It probably segfaults becaue you don't delete the resource from the
list and so it gets double freed which results in a crash (didn't
looked thorougly though).
The memory all gets freed upon scrip terrmination but I see the
advantage of freeing the resources when no longer required.
Assigned to me.
------------------------------------------------------------------------
[2001-11-29 13:39:36] mikep@oeone.com
I need a way to attach a file to this bug...
Here is the diff:
diff -ur php-4.0.6/ext/domxml/php_domxml.c
php-4.0.6-haxx0red/ext/domxml/php_domxml.c
--- php-4.0.6/ext/domxml/php_domxml.c Thu May 24 08:41:46 2001
+++ php-4.0.6-haxx0red/ext/domxml/php_domxml.c Tue Nov 13 17:26:03
2001
@@ -71,6 +71,7 @@
PHP_FE(domxml_set_attribute, NULL)
PHP_FALIAS(domxml_setattr, domxml_set_attribute, NULL)
PHP_FE(domxml_children, NULL)
+ PHP_FE(xmldocfree, NULL) //oeone
PHP_FE(domxml_new_child, NULL)
PHP_FE(domxml_node, NULL)
PHP_FE(domxml_unlink_node, NULL)
@@ -205,7 +206,7 @@
domxmltestnode_class_startup();
#endif
- le_domxmldocp = zend_register_list_destructors_ex(php_free_xml_doc,
NULL, "domxml document", module_number);
+ le_domxmldocp = zend_register_list_destructors_ex(php_free_xml_doc,
php_free_xml_doc, "domxml document", module_number);//oeone
/* Freeing the document contains freeing the complete tree.
Therefore nodes, attributes etc. may not be freed seperately.
*/
@@ -1161,6 +1162,38 @@
zend_list_addref(ret);
}
/* }}} */
+
+//oeone
+PHP_FUNCTION(xmldocfree)
+{
+ zval *id, **tmp;
+ xmlDoc *docp;
+ xmlNode *node;
+ int ret;
+
+ /* php_error( E_WARNING, "Oeone Destructor\n" ); */
+ if (ZEND_NUM_ARGS() == 0) {
+ id = getThis();
+ if (id) {
+ if (zend_hash_find(id->value.obj.properties, "doc", sizeof("doc"),
(void **)&tmp) == FAILURE) {
+ php_error(E_WARNING, "unable to find my handle property");
+ RETURN_FALSE;
+ }
+ ZEND_FETCH_RESOURCE(docp,xmlDocPtr,tmp,-1, "DomDocument",
le_domxmldocp)
+ } else {
+ RETURN_FALSE;
+ }
+ } else if ((ZEND_NUM_ARGS() != 1) || getParameters(ht, 1, &id) ==
FAILURE) {
+ WRONG_PARAM_COUNT;
+ } else {
+ if (zend_hash_find(id->value.obj.properties, "doc", sizeof("doc"),
(void **)&tmp) == FAILURE) {
+ php_error(E_WARNING, "unable to find my handle property");
+ RETURN_FALSE;
+ }
+ ZEND_FETCH_RESOURCE(docp,xmlDocPtr,tmp,-1, "DomDocument",
le_domxmldocp)
+ }
+ xmlFreeDoc(docp);
+}
/* {{{ proto object domxml_new_child([int node_handle,] string name,
string content)
Adds child node to parent node */
diff -ur php-4.0.6/ext/domxml/php_domxml.h
php-4.0.6-haxx0red/ext/domxml/php_domxml.h
--- php-4.0.6/ext/domxml/php_domxml.h Thu May 24 08:33:43 2001
+++ php-4.0.6-haxx0red/ext/domxml/php_domxml.h Tue Nov 13 17:26:03
2001
@@ -46,6 +46,7 @@
PHP_FUNCTION(domxml_add_root);
PHP_FUNCTION(domxml_intdtd);
PHP_FUNCTION(domxml_dumpmem);
+PHP_FUNCTION(xmldocfree); //oeone
/* Class Node methods */
PHP_FUNCTION(domxml_attributes);
------------------------------------------------------------------------
[2001-11-29 11:29:57] mikep@oeone.com
Here's the explanation from mostafah@oeone.com (our resident C
expert):
In the ext/domxml/php_domxml.c there is a destructor function named
php_free_xml_doc(). In the loop code that mikep@oeone.com has posted
this destructor function gets invoked after the end of the loop which
for some reason won't free up memory. We thought maybe the xmldoc
memory
should be released within the loop that is after getting an xmldoc
object into $doc and before overwriting it through the next iteration
of the loop. So we added our own xmldocfree( $doc ) function and put it
in the loop. We had no memory leak anymore but then we encountered
segfaults in the apache log file which of course was because of the
native destructor being invoked on an already released object. So maybe
even our xmldocfree wasn't working properly and the segfault was
somehow cleaning up everything behind. But anyway we are happy now
because the
memory leak is gone and the segfault does not effect our functionality.
------------------------------------------------------------------------
[2001-11-29 09:48:25] mfischer@php.net
By patching what? ext/domxml?
FYI, apache doesn't release memory it once grabs. Thats how it works.
Feedback.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/14037
--
Edit this bug report at http://bugs.php.net/?id=14037&edit=1