From: Christoph M. Becker Date: Wed, 20 May 2020 12:10:19 +0000 (+0200) Subject: Revert "Revert "Merge branch 'PHP-7.4'"" X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a582931f4255a0a022f06da613558482beeb5451;p=php Revert "Revert "Merge branch 'PHP-7.4'"" This reverts commit 28e650a, which reverted commit 046dcfb, which had to be reverted due to phpdbg issues. The culprit was that we did not properly reset `zend_handler_table` to `NULL`, which is required for SAPIs which may restart the engine after shutdown. [1] [2] --- diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index bfa41a4ffe..f1d1ff1209 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -613,4 +613,12 @@ extern "C++" { # define ZEND_PREFER_RELOAD #endif +#if defined(ZEND_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) +# define ZEND_IGNORE_LEAKS_BEGIN() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) +# define ZEND_IGNORE_LEAKS_END() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF) +#else +# define ZEND_IGNORE_LEAKS_BEGIN() +# define ZEND_IGNORE_LEAKS_END() +#endif + #endif /* ZEND_PORTABILITY_H */ diff --git a/Zend/zend_strtod.c b/Zend/zend_strtod.c index 08f8424e8c..2228e2262c 100644 --- a/Zend/zend_strtod.c +++ b/Zend/zend_strtod.c @@ -546,6 +546,7 @@ Bigint { static Bigint *freelist[Kmax+1]; static void destroy_freelist(void); +static void free_p5s(void); #ifdef ZTS static MUTEX_T dtoa_mutex; @@ -564,6 +565,8 @@ ZEND_API int zend_startup_strtod(void) /* {{{ */ ZEND_API int zend_shutdown_strtod(void) /* {{{ */ { destroy_freelist(); + free_p5s(); + #ifdef ZTS tsrm_mutex_free(dtoa_mutex); dtoa_mutex = NULL; @@ -4540,6 +4543,19 @@ static void destroy_freelist(void) FREE_DTOA_LOCK(0) } +static void free_p5s(void) +{ + Bigint **listp, *tmp; + + ACQUIRE_DTOA_LOCK(1) + listp = &p5s; + while ((tmp = *listp) != NULL) { + *listp = tmp->next; + free(tmp); + } + FREE_DTOA_LOCK(1) +} + #ifdef __cplusplus } #endif diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 1c10b8ccbf..068e1338a3 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -59579,13 +59579,18 @@ void zend_vm_init(void) VM_TRACE_START(); } +static HashTable *zend_handlers_table = NULL; + void zend_vm_dtor(void) { VM_TRACE_END(); + if (zend_handlers_table) { + zend_hash_destroy(zend_handlers_table); + free(zend_handlers_table); + zend_handlers_table = NULL; + } } -static HashTable *zend_handlers_table = NULL; - static void init_opcode_serialiser(void) { int i; diff --git a/Zend/zend_vm_execute.skl b/Zend/zend_vm_execute.skl index 27aae16391..170fc300bb 100644 --- a/Zend/zend_vm_execute.skl +++ b/Zend/zend_vm_execute.skl @@ -67,13 +67,18 @@ void {%INITIALIZER_NAME%}(void) VM_TRACE_START(); } +static HashTable *zend_handlers_table = NULL; + void zend_vm_dtor(void) { VM_TRACE_END(); + if (zend_handlers_table) { + zend_hash_destroy(zend_handlers_table); + free(zend_handlers_table); + zend_handlers_table = NULL; + } } -static HashTable *zend_handlers_table = NULL; - static void init_opcode_serialiser(void) { int i; diff --git a/ext/libxml/config.w32 b/ext/libxml/config.w32 index b11c57bc44..dd91c4b893 100644 --- a/ext/libxml/config.w32 +++ b/ext/libxml/config.w32 @@ -16,6 +16,9 @@ if (PHP_LIBXML == "yes") { ADD_DEF_FILE("ext\\libxml\\php_libxml2.def"); } PHP_INSTALL_HEADERS("ext/libxml/", "php_libxml.h"); + if (PHP_CRT_DEBUG == "yes") { + ADD_FLAG("CFLAGS_LIBXML", "/D PHP_WIN32_DEBUG_HEAP"); + } } else { WARNING("libxml support can't be enabled, iconv or libxml are missing") PHP_LIBXML = "no" diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 18da8b67da..85eaf7a026 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -700,7 +700,9 @@ PHP_LIBXML_API void php_libxml_initialize(void) { if (!_php_libxml_initialized) { /* we should be the only one's to ever init!! */ + ZEND_IGNORE_LEAKS_BEGIN(); xmlInitParser(); + ZEND_IGNORE_LEAKS_END(); _php_libxml_default_entity_loader = xmlGetExternalEntityLoader(); xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader);