ID: 14037 Comment by: luiz dot pestana at elementstudio dot com dot br Reported By: mikep at oeone dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux PHP Version: 4.0.6 Assigned To: mfischer New Comment:
I solved the problem by adding the declaration of function "domxml_doc_free_doc" in the file "ext/domxml/php_domxml.c". 260 - PHP_FE(domxml_parser_end_document, NULL) 261 - PHP_FE(domxml_parser_get_document, NULL) 262 - PHP_FE(domxml_doc_free_doc, NULL) // here Previous Comments: ------------------------------------------------------------------------ [2002-08-10 18:44:18] [EMAIL PROTECTED] 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. ------------------------------------------------------------------------ [2001-12-11 17:25:13] [EMAIL PROTECTED] De-assigned, makeing it a feature request. ------------------------------------------------------------------------ [2001-11-29 19:05:09] [EMAIL PROTECTED] 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 at oeone dot 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 at oeone dot com 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. ------------------------------------------------------------------------ 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