ID: 14037
Updated by: mfischer
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Assigned
Bug Type: DOM XML related
Operating System: Linux
PHP Version: 4.0.6
Old Assigned To: 
Assigned To: mfischer
New Comment:

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.

Previous Comments:
------------------------------------------------------------------------

[2001-11-29 13:39:36] [EMAIL PROTECTED]

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] [EMAIL PROTECTED]

Here's the explanation from [EMAIL PROTECTED] (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 [EMAIL PROTECTED] 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] [EMAIL PROTECTED]

By patching what? ext/domxml?

FYI, apache doesn't release memory it once grabs. Thats how it works.

Feedback.

------------------------------------------------------------------------

[2001-11-29 09:42:22] [EMAIL PROTECTED]

As stated, the memory used by Apache sky rockets... On my machine, it goes up to about 
90% or so.
We're working on a patch to this bug, we've got the memory leak fixed by closing the 
file using a function we wrote, but unfortunately that ended up causing a segfault in 
Apache. 
When we fix that problem, we'll post the fix here.

------------------------------------------------------------------------

[2001-11-29 09:38:04] [EMAIL PROTECTED]

What do you define as 'memory leak' ? Error output in apaches log?

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/?id=14037


Edit this bug report at http://bugs.php.net/?id=14037&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to