Permalink
Browse files

Fixed bug #51552 (debug_backtrace() causes segmentation fault and/or …

…memory issues)
  • Loading branch information...
1 parent afcb62b commit d24c14cb5944167e413751963a608030f76c1ae9 Dmitry Stogov committed Jun 11, 2010
Showing with 32 additions and 0 deletions.
  1. +9 −0 ext/standard/array.c
  2. +23 −0 ext/standard/tests/array/bug51552.phpt
View
9 ext/standard/array.c
@@ -1057,6 +1057,9 @@ static int php_array_walk(HashTable *target_hash, zval **userdata, int recursive
/* Set up known arguments */
args[1] = &key;
args[2] = userdata;
+ if (userdata) {
+ Z_ADDREF_PP(userdata);
+ }
zend_hash_internal_pointer_reset_ex(target_hash, &pos);
@@ -1076,6 +1079,9 @@ static int php_array_walk(HashTable *target_hash, zval **userdata, int recursive
thash = Z_ARRVAL_PP(args[0]);
if (thash->nApplyCount > 1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
+ if (userdata) {
+ zval_ptr_dtor(userdata);
+ }
return 0;
}
@@ -1126,6 +1132,9 @@ static int php_array_walk(HashTable *target_hash, zval **userdata, int recursive
zend_hash_move_forward_ex(target_hash, &pos);
}
+ if (userdata) {
+ zval_ptr_dtor(userdata);
+ }
return 0;
}
/* }}} */
View
23 ext/standard/tests/array/bug51552.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #51552 (debug_backtrace() causes segmentation fault and/or memory issues)
+--FILE--
+<?php
+function walk($element, $key, $p) {
+ $backtrace = debug_backtrace();
+ echo "$element\n";
+}
+
+$a = array(1,2,3,4,5,6,7,8,9,10);
+array_walk($a, 'walk', 'testthis');
+?>
+--EXPECT--
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10

0 comments on commit d24c14c

Please sign in to comment.