From 69a93d2fd79b3e4719e0bb95ee75a6d13275ec3e Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 23 Feb 2014 21:53:48 +0800 Subject: [PATCH] Fixed segfault in ext/standard/tests/strings/bug49785.phpt --- ext/standard/array.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index f16cc40969..ed56b28cf9 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2255,20 +2255,26 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS thash->nApplyCount--; } } else { - Z_ADDREF_P(src_entry); + if (Z_REFCOUNTED_P(src_entry)) { + Z_ADDREF_P(src_entry); + } zend_hash_next_index_insert(Z_ARRVAL_P(dest_entry), &src_zval); } if (tmp) { zval_ptr_dtor(tmp); } } else { - Z_ADDREF_P(src_entry); + if (Z_REFCOUNTED_P(src_entry)) { + Z_ADDREF_P(src_entry); + } zend_hash_update(dest, string_key, src_entry); } break; case HASH_KEY_IS_LONG: - Z_ADDREF_P(src_entry); + if (Z_REFCOUNTED_P(src_entry)) { + Z_ADDREF_P(src_entry); + } zend_hash_next_index_insert(dest, src_entry); break; } @@ -4324,11 +4330,11 @@ PHP_FUNCTION(array_map) zend_hash_internal_pointer_reset_ex(Z_ARRVAL(arrays[i]), &array_pos[i]); } - efree(arrays); /* Short-circuit: if no callback and only one array, just return it. */ if (!ZEND_FCI_INITIALIZED(fci) && n_arrays == 1) { RETVAL_ZVAL(args[0], 1, 0); + efree(arrays); efree(array_len); efree(array_pos); efree(args); @@ -4403,6 +4409,7 @@ PHP_FUNCTION(array_map) } } + efree(arrays); efree(params); efree(array_len); efree(array_pos); -- 2.40.0