@@ -381,11 +381,19 @@ static zval *php_dom_xpath_callback_fetch_args(xmlXPathParserContextPtr ctxt, ui
381381 return params ;
382382}
383383
384- static void php_dom_xpath_callback_cleanup_args (zval * params , uint32_t param_count )
384+ static void php_dom_xpath_callback_cleanup_args (php_dom_xpath_callbacks * xpath_callbacks , zval * params , uint32_t param_count )
385385{
386386 if (params ) {
387387 for (uint32_t i = 0 ; i < param_count ; i ++ ) {
388- zval_ptr_dtor (& params [i ]);
388+ zval * param = & params [i ];
389+ if (Z_TYPE_P (param ) == IS_OBJECT || Z_TYPE_P (param ) == IS_ARRAY ) {
390+ if (xpath_callbacks -> node_list == NULL ) {
391+ xpath_callbacks -> node_list = zend_new_array (0 );
392+ }
393+ zend_hash_next_index_insert_new (xpath_callbacks -> node_list , param );
394+ } else {
395+ zval_ptr_dtor (param );
396+ }
389397 }
390398 efree (params );
391399 }
@@ -484,7 +492,7 @@ PHP_DOM_EXPORT zend_result php_dom_xpath_callbacks_call_php_ns(php_dom_xpath_cal
484492
485493cleanup :
486494 xmlXPathFreeObject (obj );
487- php_dom_xpath_callback_cleanup_args (params , param_count );
495+ php_dom_xpath_callback_cleanup_args (xpath_callbacks , params , param_count );
488496cleanup_no_obj :
489497 if (UNEXPECTED (result != SUCCESS )) {
490498 /* Push sentinel value */
@@ -512,7 +520,7 @@ PHP_DOM_EXPORT zend_result php_dom_xpath_callbacks_call_custom_ns(php_dom_xpath_
512520
513521 zend_result result = php_dom_xpath_callback_dispatch (xpath_callbacks , ns , ctxt , params , param_count , function_name , function_name_length );
514522
515- php_dom_xpath_callback_cleanup_args (params , param_count );
523+ php_dom_xpath_callback_cleanup_args (xpath_callbacks , params , param_count );
516524 if (UNEXPECTED (result != SUCCESS )) {
517525 /* Push sentinel value */
518526 valuePush (ctxt , xmlXPathNewString ((const xmlChar * ) "" ));
0 commit comments