Skip to content

Commit 21698c1

Browse files
committed
Fixed huge memory leak in ZTS mode (backport from HEAD)
1 parent 9023667 commit 21698c1

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Zend/zend.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# define GLOBAL_FUNCTION_TABLE CG(function_table)
3939
# define GLOBAL_CLASS_TABLE CG(class_table)
4040
# define GLOBAL_AUTO_GLOBALS_TABLE CG(auto_globals)
41+
# define GLOBAL_CONSTANTS_TABLE EG(zend_constants)
4142
#endif
4243

4344
#if defined(ZEND_WIN32) && ZEND_DEBUG
@@ -88,6 +89,7 @@ HashTable *global_function_table;
8889
HashTable *global_class_table;
8990
HashTable *global_constants_table;
9091
HashTable *global_auto_globals_table;
92+
static HashTable *global_persistent_list = NULL;
9193
#endif
9294

9395
ZEND_API zend_utility_values zend_uv;
@@ -486,6 +488,13 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS
486488
static void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC)
487489
{
488490
zend_ini_shutdown(TSRMLS_C);
491+
if (&executor_globals->persistent_list != global_persistent_list) {
492+
zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
493+
}
494+
if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
495+
zend_hash_destroy(executor_globals->zend_constants);
496+
free(executor_globals->zend_constants);
497+
}
489498
}
490499

491500

@@ -682,6 +691,7 @@ void zend_post_startup(TSRMLS_D)
682691
compiler_globals_ctor(compiler_globals, tsrm_ls);
683692
free(EG(zend_constants));
684693
executor_globals_ctor(executor_globals, tsrm_ls);
694+
global_persistent_list = &EG(persistent_list);
685695
zend_new_thread_end_handler(tsrm_thread_id() TSRMLS_CC);
686696
}
687697
#endif
@@ -691,9 +701,6 @@ void zend_shutdown(TSRMLS_D)
691701
{
692702
#ifdef ZEND_WIN32
693703
zend_shutdown_timeout_thread();
694-
#endif
695-
#ifndef ZTS
696-
zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
697704
#endif
698705
zend_hash_graceful_reverse_destroy(&module_registry);
699706

@@ -706,16 +713,18 @@ void zend_shutdown(TSRMLS_D)
706713
zend_shutdown_extensions(TSRMLS_C);
707714
free(zend_version_info);
708715

709-
zend_shutdown_constants(TSRMLS_C);
710716
free(GLOBAL_FUNCTION_TABLE);
711717
free(GLOBAL_CLASS_TABLE);
712-
#ifdef ZTS
713-
zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
718+
714719
zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
715720
free(GLOBAL_CONSTANTS_TABLE);
721+
722+
zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
723+
#ifdef ZTS
716724
GLOBAL_FUNCTION_TABLE = NULL;
717725
GLOBAL_CLASS_TABLE = NULL;
718726
GLOBAL_AUTO_GLOBALS_TABLE = NULL;
727+
GLOBAL_CONSTANTS_TABLE = NULL;
719728
#endif
720729
zend_destroy_rsrc_list_dtors();
721730
}

0 commit comments

Comments
 (0)