Skip to content

Commit 3429e33

Browse files
committed
fixed big bad memory leak in xpath objects.
1 parent 5d554c2 commit 3429e33

File tree

1 file changed

+2
-81
lines changed

1 file changed

+2
-81
lines changed

ext/domxml/php_domxml.c

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -698,19 +698,6 @@ static void php_free_xpath_context(zend_rsrc_list_entry *rsrc TSRMLS_DC)
698698
xmlXPathFreeContext(ctx);
699699
}
700700
}
701-
702-
static void php_free_xpath_object(zend_rsrc_list_entry *rsrc TSRMLS_DC)
703-
{
704-
xmlXPathObjectPtr obj = (xmlXPathObjectPtr) rsrc->ptr;
705-
706-
if (obj) {
707-
if (obj->user) {
708-
zval *wrapper = obj->user;
709-
zval_ptr_dtor(&wrapper);
710-
}
711-
xmlXPathFreeObject(obj);
712-
}
713-
}
714701
#endif
715702

716703
static void php_free_xml_parser(zend_rsrc_list_entry *rsrc TSRMLS_DC)
@@ -843,79 +830,12 @@ void *php_xpath_get_object(zval *wrapper, int rsrc_type1, int rsrc_type2 TSRMLS_
843830
return obj;
844831
}
845832

846-
847-
static void xpath_object_set_data(void *obj, zval *wrapper)
848-
{
849-
/*
850-
char tmp[20];
851-
sprintf(tmp, "%08X", obj);
852-
fprintf(stderr, "Adding %s to hash\n", tmp);
853-
*/
854-
((xmlXPathObjectPtr) obj)->user = wrapper;
855-
}
856-
857-
858-
static zval *xpath_object_get_data(void *obj)
859-
{
860-
/*
861-
char tmp[20];
862-
sprintf(tmp, "%08X", obj);
863-
fprintf(stderr, "Trying getting %s from hash ...", tmp);
864-
if(((xmlXPathObjectPtr) obj)->user)
865-
fprintf(stderr, " found\n");
866-
else
867-
fprintf(stderr, " not found\n");
868-
*/
869-
return ((zval *) (((xmlXPathObjectPtr) obj)->user));
870-
}
871-
872-
873-
static void php_xpath_set_object(zval *wrapper, void *obj, int rsrc_type)
874-
{
875-
zval *handle, *addr;
876-
877-
MAKE_STD_ZVAL(handle);
878-
Z_TYPE_P(handle) = IS_LONG;
879-
Z_LVAL_P(handle) = zend_list_insert(obj, rsrc_type);
880-
881-
MAKE_STD_ZVAL(addr);
882-
Z_TYPE_P(addr) = IS_LONG;
883-
Z_LVAL_P(addr) = (int) obj;
884-
885-
zend_hash_index_update(Z_OBJPROP_P(wrapper), 0, &handle, sizeof(zval *), NULL);
886-
zend_hash_index_update(Z_OBJPROP_P(wrapper), 1, &addr, sizeof(zval *), NULL);
887-
zval_add_ref(&wrapper);
888-
xpath_object_set_data(obj, wrapper);
889-
}
890-
891833
static zval *php_xpathobject_new(xmlXPathObjectPtr obj, int *found TSRMLS_DC)
892834
{
893835
zval *wrapper;
894836

895-
*found = 0;
896-
897-
if (!obj) {
898-
MAKE_STD_ZVAL(wrapper);
899-
ZVAL_NULL(wrapper);
900-
return wrapper;
901-
}
902-
903-
if ((wrapper = (zval *) xpath_object_get_data((void *) obj))) {
904-
zval_add_ref(&wrapper);
905-
*found = 1;
906-
return wrapper;
907-
}
908-
909837
MAKE_STD_ZVAL(wrapper);
910838
object_init_ex(wrapper, xpathobject_class_entry);
911-
912-
/*
913-
rsrc_type = le_xpathobjectp;
914-
php_xpath_set_object(wrapper, (void *) obj, rsrc_type);
915-
*/
916-
917-
php_xpath_set_object(wrapper, (void *) obj, le_xpathobjectp);
918-
919839
return (wrapper);
920840
}
921841

@@ -1575,7 +1495,7 @@ PHP_MINIT_FUNCTION(domxml)
15751495

15761496
#if defined(LIBXML_XPATH_ENABLED)
15771497
le_xpathctxp = zend_register_list_destructors_ex(php_free_xpath_context, NULL, "xpathcontext", module_number);
1578-
le_xpathobjectp = zend_register_list_destructors_ex(php_free_xpath_object, NULL, "xpathobject", module_number);
1498+
le_xpathobjectp = zend_register_list_destructors_ex(NULL, NULL, "xpathobject", module_number);
15791499
#endif
15801500

15811501
/* le_domxmlnsp = register_list_destructors(NULL, NULL); */
@@ -4853,6 +4773,7 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
48534773
break;
48544774
}
48554775

4776+
xmlXPathFreeObject(xpathobjp);
48564777
*return_value = *rv;
48574778
FREE_ZVAL(rv);
48584779
}

0 commit comments

Comments
 (0)