From: Marcus Boerger Date: Sun, 10 Aug 2008 21:52:05 +0000 (+0000) Subject: - Fix memleak, Zend's built-in functions get copied before we copy all X-Git-Tag: BEFORE_HEAD_NS_CHANGE~787 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aea4ea120fbf3539eed29363ea89242d472a0e75;p=php - Fix memleak, Zend's built-in functions get copied before we copy all functions, thus ending up in the name and param definitions copied twice because zend_register_funciton already copies them. - Also Be able to deallocate Zend's built-in functions and do so when appropriate. - After unregistering Zend's built-in functions only dl() is left and that seems to be fine. --- diff --git a/Zend/zend.c b/Zend/zend.c index b232bd32be..9cde763a82 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1045,7 +1045,7 @@ static void unicode_globals_dtor(zend_unicode_globals *unicode_globals TSRMLS_DC void zend_init_opcodes_handlers(void); -int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions) /* {{{ */ +int zend_startup(zend_utility_functions *utility_functions, char **extensions) /* {{{ */ { #ifdef ZTS zend_compiler_globals *compiler_globals; @@ -1170,10 +1170,6 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i zend_init_exception_op(TSRMLS_C); #endif - if (start_builtin_functions) { - zend_startup_builtin_functions(TSRMLS_C); - } - zend_ini_startup(TSRMLS_C); #ifdef ZTS @@ -1209,6 +1205,7 @@ void zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */ ucnv_close(UG(runtime_encoding_conv)); UG(runtime_encoding_conv) = old_runtime_encoding_conv; } + zend_startup_builtin_functions(TSRMLS_C); } /* }}} */ @@ -1248,6 +1245,7 @@ void zend_shutdown(TSRMLS_D) /* {{{ */ #endif zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC); zend_hash_graceful_reverse_destroy(&module_registry); + zend_shutdown_builtin_functions(TSRMLS_C); zend_hash_destroy(GLOBAL_FUNCTION_TABLE); zend_hash_destroy(GLOBAL_CLASS_TABLE); diff --git a/Zend/zend.h b/Zend/zend.h index c890cb240b..949fea3916 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -572,7 +572,7 @@ typedef int (*zend_write_func_t)(const char *str, uint str_length); /* default engine string type */ #define ZEND_STR_TYPE (UG(unicode) ? IS_UNICODE : IS_STRING) -int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions); +int zend_startup(zend_utility_functions *utility_functions, char **extensions); void zend_shutdown(TSRMLS_D); void zend_register_standard_ini_entries(TSRMLS_D); void zend_post_startup(TSRMLS_D); diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 715219a54c..bf1caf8a98 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -416,6 +416,12 @@ int zend_startup_builtin_functions(TSRMLS_D) /* {{{ */ } /* }}} */ +void zend_shutdown_builtin_functions(TSRMLS_D) /* {{{ */ +{ + zend_unregister_functions(builtin_functions, -1, NULL TSRMLS_CC); +} +/* }}} */ + /* {{{ proto string zend_version(void) U Get the version of the Zend Engine */ ZEND_FUNCTION(zend_version) diff --git a/Zend/zend_builtin_functions.h b/Zend/zend_builtin_functions.h index deb313eeb2..9729f42095 100644 --- a/Zend/zend_builtin_functions.h +++ b/Zend/zend_builtin_functions.h @@ -23,6 +23,7 @@ #define ZEND_BUILTIN_FUNCTIONS_H int zend_startup_builtin_functions(TSRMLS_D); +int zend_shutdown_builtin_functions(TSRMLS_D); BEGIN_EXTERN_C() ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int provide_object TSRMLS_DC); diff --git a/main/main.c b/main/main.c index 1ba177eddf..859a4655dc 100644 --- a/main/main.c +++ b/main/main.c @@ -1838,7 +1838,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod zuf.vspprintf_function = vspprintf; zuf.getenv_function = sapi_getenv; zuf.resolve_path_function = php_resolve_path_for_zend; - zend_startup(&zuf, NULL, 1); + zend_startup(&zuf, NULL); #ifdef ZTS executor_globals = ts_resource(executor_globals_id);