From: Dmitry Stogov Date: Mon, 27 Aug 2018 09:47:32 +0000 (+0300) Subject: Avoid function copying X-Git-Tag: php-7.4.0alpha1~2051 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02eded868c5fb307ce2b87042db1fd9a2e6ef1f7;p=php Avoid function copying --- diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 9f974d922a..2b3900164a 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1057,21 +1057,21 @@ ZEND_API int do_bind_function(zval *lcname) /* {{{ */ rtd_key = lcname + 1; zv = zend_hash_find_ex(EG(function_table), Z_STR_P(rtd_key), 1); - function = (zend_function*)Z_PTR_P(zv); - new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); - memcpy(new_function, function, sizeof(zend_op_array)); - if (zend_hash_add_ptr(EG(function_table), Z_STR_P(lcname), new_function) == NULL) { - do_bind_function_error(Z_STR_P(lcname), &new_function->op_array, 0); - return FAILURE; - } else { + new_function = function = (zend_function*)Z_PTR_P(zv); + if (function->op_array.static_variables + && !(function->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) { + new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); + memcpy(new_function, function, sizeof(zend_op_array)); + function->op_array.static_variables = NULL; /* NULL out the unbound function */ if (function->op_array.refcount) { (*function->op_array.refcount)++; } - if (!(function->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) { - function->op_array.static_variables = NULL; /* NULL out the unbound function */ - } - return SUCCESS; } + if (UNEXPECTED(zend_hash_add_ptr(EG(function_table), Z_STR_P(lcname), new_function) == NULL)) { + do_bind_function_error(Z_STR_P(lcname), &new_function->op_array, 0); + return FAILURE; + } + return SUCCESS; } /* }}} */