From 7680194a930165f50194a48e324d11001aef3465 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 18 Sep 2015 17:27:39 +0800 Subject: [PATCH] Fixed bug #70481 (Memory leak in auto_global_copy_ctor() in ZTS build) --- NEWS | 3 +++ Zend/zend.c | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 93b8999668..fb99eb0c4e 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 01 Oct 2015, PHP 7.0.0 RC 4 +- Core: + . Fixed bug #70481 (Memory leak in auto_global_copy_ctor() in ZTS build). + (Laruence) 17 Sep 2015, PHP 7.0.0 RC 3 diff --git a/Zend/zend.c b/Zend/zend.c index c521df9ce2..0a70ccc3b5 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -446,26 +446,34 @@ static void zend_init_call_trampoline_op(void) /* {{{ */ } /* }}} */ +static void auto_global_dtor(zval *zv) /* {{{ */ +{ + free(Z_PTR_P(zv)); +} +/* }}} */ + #ifdef ZTS -static void function_copy_ctor(zval *zv) +static void function_copy_ctor(zval *zv) /* {{{ */ { zend_function *old_func = Z_FUNC_P(zv); Z_FUNC_P(zv) = pemalloc(sizeof(zend_internal_function), 1); memcpy(Z_FUNC_P(zv), old_func, sizeof(zend_internal_function)); function_add_ref(Z_FUNC_P(zv)); } +/* }}} */ -static void auto_global_copy_ctor(zval *zv) +static void auto_global_copy_ctor(zval *zv) /* {{{ */ { zend_auto_global *old_ag = (zend_auto_global *) Z_PTR_P(zv); zend_auto_global *new_ag = pemalloc(sizeof(zend_auto_global), 1); - new_ag->name = zend_string_copy(old_ag->name); + new_ag->name = old_ag->name; new_ag->auto_global_callback = old_ag->auto_global_callback; new_ag->jit = old_ag->jit; Z_PTR_P(zv) = new_ag; } +/* }}} */ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{{ */ { @@ -482,7 +490,7 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{ zend_set_default_compile_time_values(); compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0); + zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, auto_global_dtor, 1, 0); zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, auto_global_copy_ctor); compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table); @@ -609,12 +617,6 @@ static void module_destructor_zval(zval *zv) /* {{{ */ } /* }}} */ -static void auto_global_dtor(zval *zv) /* {{{ */ -{ - free(Z_PTR_P(zv)); -} -/* }}} */ - static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */ { zval globals; -- 2.40.0