Skip to content

Commit aea4ea1

Browse files
committed
- 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.
1 parent b9b83ec commit aea4ea1

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

Zend/zend.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ static void unicode_globals_dtor(zend_unicode_globals *unicode_globals TSRMLS_DC
10451045

10461046
void zend_init_opcodes_handlers(void);
10471047

1048-
int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions) /* {{{ */
1048+
int zend_startup(zend_utility_functions *utility_functions, char **extensions) /* {{{ */
10491049
{
10501050
#ifdef ZTS
10511051
zend_compiler_globals *compiler_globals;
@@ -1170,10 +1170,6 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
11701170
zend_init_exception_op(TSRMLS_C);
11711171
#endif
11721172

1173-
if (start_builtin_functions) {
1174-
zend_startup_builtin_functions(TSRMLS_C);
1175-
}
1176-
11771173
zend_ini_startup(TSRMLS_C);
11781174

11791175
#ifdef ZTS
@@ -1209,6 +1205,7 @@ void zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
12091205
ucnv_close(UG(runtime_encoding_conv));
12101206
UG(runtime_encoding_conv) = old_runtime_encoding_conv;
12111207
}
1208+
zend_startup_builtin_functions(TSRMLS_C);
12121209
}
12131210
/* }}} */
12141211

@@ -1248,6 +1245,7 @@ void zend_shutdown(TSRMLS_D) /* {{{ */
12481245
#endif
12491246
zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
12501247
zend_hash_graceful_reverse_destroy(&module_registry);
1248+
zend_shutdown_builtin_functions(TSRMLS_C);
12511249

12521250
zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
12531251
zend_hash_destroy(GLOBAL_CLASS_TABLE);

Zend/zend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ typedef int (*zend_write_func_t)(const char *str, uint str_length);
572572
/* default engine string type */
573573
#define ZEND_STR_TYPE (UG(unicode) ? IS_UNICODE : IS_STRING)
574574

575-
int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions);
575+
int zend_startup(zend_utility_functions *utility_functions, char **extensions);
576576
void zend_shutdown(TSRMLS_D);
577577
void zend_register_standard_ini_entries(TSRMLS_D);
578578
void zend_post_startup(TSRMLS_D);

Zend/zend_builtin_functions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ int zend_startup_builtin_functions(TSRMLS_D) /* {{{ */
416416
}
417417
/* }}} */
418418

419+
void zend_shutdown_builtin_functions(TSRMLS_D) /* {{{ */
420+
{
421+
zend_unregister_functions(builtin_functions, -1, NULL TSRMLS_CC);
422+
}
423+
/* }}} */
424+
419425
/* {{{ proto string zend_version(void) U
420426
Get the version of the Zend Engine */
421427
ZEND_FUNCTION(zend_version)

Zend/zend_builtin_functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define ZEND_BUILTIN_FUNCTIONS_H
2424

2525
int zend_startup_builtin_functions(TSRMLS_D);
26+
int zend_shutdown_builtin_functions(TSRMLS_D);
2627

2728
BEGIN_EXTERN_C()
2829
ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int provide_object TSRMLS_DC);

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
18381838
zuf.vspprintf_function = vspprintf;
18391839
zuf.getenv_function = sapi_getenv;
18401840
zuf.resolve_path_function = php_resolve_path_for_zend;
1841-
zend_startup(&zuf, NULL, 1);
1841+
zend_startup(&zuf, NULL);
18421842

18431843
#ifdef ZTS
18441844
executor_globals = ts_resource(executor_globals_id);

0 commit comments

Comments
 (0)