hi! this patch is against current cvs. it contains some trivial cleanups and fixes for several memory leaks, where memory that gets malloc()ed in libxml2 is not free()d. please apply...
additionally, this patch changes get_attribute() to return FALSE instead of an empty string if the attribute does not exists. without this change, php code cannot distinguish between a missing and an empty attribute. i hope this gets applied too... regards, -lukas
Index: ext/domxml/php_domxml.c =================================================================== RCS file: /repository/php4/ext/domxml/php_domxml.c,v retrieving revision 1.132 diff -u -r1.132 php_domxml.c --- ext/domxml/php_domxml.c 27 Mar 2002 21:45:45 -0000 1.132 +++ ext/domxml/php_domxml.c 4 Apr 2002 10:28:29 -0000 @@ -744,9 +744,7 @@ { zval *wrapper; - if (! found) { *found = 0; - } if (!obj) { MAKE_STD_ZVAL(wrapper); @@ -851,9 +849,7 @@ zval *wrapper; int rsrc_type; - if (! found) { *found = 0; - } if (!obj) { MAKE_STD_ZVAL(wrapper); @@ -937,9 +933,7 @@ char *content; int rsrc_type; - if (! found) { *found = 0; - } if (!obj) { MAKE_STD_ZVAL(wrapper); @@ -976,6 +970,7 @@ if (content) { add_property_long(wrapper, "type", Z_TYPE_P(nodep)); add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1); + xmlFree(content); } break; } @@ -989,6 +984,7 @@ if (content) { add_property_long(wrapper, "type", Z_TYPE_P(nodep)); add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1); + xmlFree(content); } break; } @@ -1000,8 +996,10 @@ rsrc_type = le_domxmlpip; content = xmlNodeGetContent(nodep); add_property_stringl(wrapper, "target", (char *) nodep->name, strlen(nodep->name), 1); - if (content) + if (content) { add_property_stringl(wrapper, "data", (char *) content, strlen(content), 1); + xmlFree(content); + } break; } @@ -1024,8 +1022,10 @@ add_property_stringl(wrapper, "name", (char *) nodep->name, strlen(nodep->name), 1); if (Z_TYPE_P(obj) == XML_ENTITY_REF_NODE) { content = xmlNodeGetContent(nodep); - if (content) + if (content) { add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1); + xmlFree(content); + } } break; } @@ -1038,8 +1038,10 @@ add_property_stringl(wrapper, "name", (char *) attrp->name, strlen(attrp->name), 1); add_property_long(wrapper, "type", Z_TYPE_P(attrp)); content = xmlNodeGetContent((xmlNodePtr) attrp); - if (content) + if (content) { add_property_stringl(wrapper, "value", (char *) content, strlen(content), 1); + xmlFree(content); + } break; } @@ -1093,8 +1095,10 @@ rsrc_type = le_domxmlcdatap; content = xmlNodeGetContent(nodep); add_property_long(wrapper, "type", Z_TYPE_P(nodep)); - if (content) + if (content) { add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1); + xmlFree(content); + } break; } @@ -1749,7 +1753,7 @@ } /* }}} */ -/* {{{ proto object domxml_node_prefix(void) +/* {{{ proto string domxml_node_prefix(void) Returns namespace prefix of node */ PHP_FUNCTION(domxml_node_prefix) { @@ -2103,7 +2107,8 @@ RETURN_FALSE; } - RETURN_STRING(mem,1); + RETVAL_STRING(mem,1); + xmlFree(mem); } /* }}} */ @@ -2201,9 +2206,10 @@ value = xmlGetProp(nodep, name); if (!value) { - RETURN_EMPTY_STRING(); + RETURN_FALSE; } else { - RETURN_STRING(value, 1); + RETVAL_STRING(value, 1); + xmlFree(value); } } /* }}} */ @@ -2242,8 +2248,7 @@ DOMXML_PARAM_TWO(nodep, id, le_domxmlelementp, "s", &name, &name_len); attrp = xmlHasProp(nodep,name); - if (attrp == NULL) - { + if (attrp == NULL) { RETURN_FALSE; } xmlUnlinkNode((xmlNodePtr)attrp); @@ -2263,8 +2268,7 @@ DOMXML_PARAM_TWO(nodep, id, le_domxmlelementp, "s", &name, &name_len); attrp = xmlHasProp(nodep,name); - if (attrp == NULL) - { + if (attrp == NULL) { RETURN_FALSE; } DOMXML_RET_OBJ(rv, (xmlNodePtr) attrp, &ret); @@ -2990,9 +2994,12 @@ htmlDocDumpMemory(docp, &mem, &size); if (!size) { + if (mem) + xmlFree(mem); RETURN_FALSE; } RETURN_STRINGL(mem, size, 1); + xmlFree(mem); } /* }}} */ @@ -3573,9 +3580,7 @@ zval *wrapper; int rsrc_type; - if (! found) { *found = 0; - } if (!obj) { MAKE_STD_ZVAL(wrapper);
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php