diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index 5d1ae304098da..09ff8cc49279e 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -576,27 +576,6 @@ void ts_free_id(ts_rsrc_id id) TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully freed resource id %d", id)); }/*}}}*/ -TSRM_API void ts_apply_for_id(ts_rsrc_id id, void (*cb)(void *)) -{ - int rsrc_id = TSRM_UNSHUFFLE_RSRC_ID(id); - - tsrm_mutex_lock(tsmm_mutex); - - if (tsrm_tls_table && resource_types_table) { - for (int i = 0; i < tsrm_tls_table_size; i++) { - tsrm_tls_entry *p = tsrm_tls_table[i]; - - while (p) { - if (p->count > rsrc_id && p->storage[rsrc_id]) { - cb(p->storage[rsrc_id]); - } - p = p->next; - } - } - } - - tsrm_mutex_unlock(tsmm_mutex); -} /* * Utility Functions diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index c9e8edd37224b..3bb32e4da289a 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -104,9 +104,6 @@ TSRM_API void ts_free_thread(void); /* deallocates all occurrences of a given id */ TSRM_API void ts_free_id(ts_rsrc_id id); -/* Runs a callback on all resources of the given id. - * The caller is responsible for ensuring the underlying resources don't data-race. */ -TSRM_API void ts_apply_for_id(ts_rsrc_id id, void (*cb)(void *)); /* Debug support */ #define TSRM_ERROR_LEVEL_ERROR 1 diff --git a/Zend/zend.c b/Zend/zend.c index f8628079f9f1e..12efe56a63b05 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -826,19 +826,13 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{ } /* }}} */ -static void executor_globals_persistent_list_dtor(void *storage) +static void executor_globals_dtor(zend_executor_globals *executor_globals) /* {{{ */ { - zend_executor_globals *executor_globals = storage; + zend_ini_dtor(executor_globals->ini_directives); if (&executor_globals->persistent_list != global_persistent_list) { zend_destroy_rsrc_list(&executor_globals->persistent_list); } -} - -static void executor_globals_dtor(zend_executor_globals *executor_globals) /* {{{ */ -{ - zend_ini_dtor(executor_globals->ini_directives); - if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) { zend_hash_destroy(executor_globals->zend_constants); free(executor_globals->zend_constants); @@ -1128,9 +1122,6 @@ void zend_shutdown(void) /* {{{ */ zend_vm_dtor(); zend_destroy_rsrc_list(&EG(persistent_list)); -#ifdef ZTS - ts_apply_for_id(executor_globals_id, executor_globals_persistent_list_dtor); -#endif zend_destroy_modules(); virtual_cwd_deactivate(); @@ -1183,8 +1174,6 @@ void zend_shutdown(void) /* {{{ */ #endif zend_destroy_rsrc_list_dtors(); - zend_unload_modules(); - zend_optimizer_shutdown(); startup_done = false; } diff --git a/Zend/zend.h b/Zend/zend.h index bc252f4706b0c..091a3dab213d9 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -280,7 +280,6 @@ void zend_shutdown(void); void zend_register_standard_ini_entries(void); zend_result zend_post_startup(void); void zend_set_utility_values(zend_utility_values *utility_values); -void zend_unload_modules(void); ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno); ZEND_API size_t zend_get_page_size(void); diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 2a16f24250ebe..0667842dd2587 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -41,7 +41,6 @@ ZEND_API HashTable module_registry; static zend_module_entry **module_request_startup_handlers; static zend_module_entry **module_request_shutdown_handlers; static zend_module_entry **module_post_deactivate_handlers; -static zend_module_entry **modules_dl_loaded; static zend_class_entry **class_cleanup_handlers; @@ -2399,7 +2398,6 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ int startup_count = 0; int shutdown_count = 0; int post_deactivate_count = 0; - int dl_loaded_count = 0; zend_class_entry *ce; int class_count = 0; @@ -2414,9 +2412,6 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ if (module->post_deactivate_func) { post_deactivate_count++; } - if (module->handle) { - dl_loaded_count++; - } } ZEND_HASH_FOREACH_END(); module_request_startup_handlers = (zend_module_entry**)realloc( module_request_startup_handlers, @@ -2429,9 +2424,6 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ module_request_shutdown_handlers[shutdown_count] = NULL; module_post_deactivate_handlers = module_request_shutdown_handlers + shutdown_count + 1; module_post_deactivate_handlers[post_deactivate_count] = NULL; - /* Cannot reuse module_request_startup_handlers because it is freed in zend_destroy_modules, which happens before zend_unload_modules. */ - modules_dl_loaded = realloc(modules_dl_loaded, sizeof(zend_module_entry*) * (dl_loaded_count + 1)); - modules_dl_loaded[dl_loaded_count] = NULL; startup_count = 0; ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) { @@ -2444,9 +2436,6 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ if (module->post_deactivate_func) { module_post_deactivate_handlers[--post_deactivate_count] = module; } - if (module->handle) { - modules_dl_loaded[--dl_loaded_count] = module; - } } ZEND_HASH_FOREACH_END(); /* Collect internal classes with static members */ @@ -3250,22 +3239,17 @@ void module_destructor(zend_module_entry *module) /* {{{ */ clean_module_functions(module); } -#if ZEND_RC_DEBUG - zend_rc_debug = orig_rc_debug; -#endif -} -/* }}} */ - -void module_registry_unload(const zend_module_entry *module) -{ #if HAVE_LIBDL - if (!getenv("ZEND_DONT_UNLOAD_MODULES")) { + if (module->handle && !getenv("ZEND_DONT_UNLOAD_MODULES")) { DL_UNLOAD(module->handle); } -#else - ZEND_IGNORE_VALUE(module); +#endif + +#if ZEND_RC_DEBUG + zend_rc_debug = orig_rc_debug; #endif } +/* }}} */ ZEND_API void zend_activate_modules(void) /* {{{ */ { @@ -3311,18 +3295,6 @@ ZEND_API void zend_deactivate_modules(void) /* {{{ */ } /* }}} */ -void zend_unload_modules(void) /* {{{ */ -{ - zend_module_entry **modules = modules_dl_loaded; - while (*modules) { - module_registry_unload(*modules); - modules++; - } - free(modules_dl_loaded); - modules_dl_loaded = NULL; -} -/* }}} */ - ZEND_API void zend_post_deactivate_modules(void) /* {{{ */ { if (EG(full_tables_cleanup)) { @@ -3341,9 +3313,6 @@ ZEND_API void zend_post_deactivate_modules(void) /* {{{ */ break; } module_destructor(module); - if (module->handle) { - module_registry_unload(module); - } zend_string_release_ex(key, 0); } ZEND_HASH_MAP_FOREACH_END_DEL(); } else { diff --git a/Zend/zend_modules.h b/Zend/zend_modules.h index f3f6ca826817d..8c90e763a12fc 100644 --- a/Zend/zend_modules.h +++ b/Zend/zend_modules.h @@ -125,7 +125,7 @@ extern ZEND_API HashTable module_registry; void module_destructor(zend_module_entry *module); int module_registry_request_startup(zend_module_entry *module); -void module_registry_unload(const zend_module_entry *module); +int module_registry_unload_temp(const zend_module_entry *module); END_EXTERN_C() #endif diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index 1866a8f14d12d..cd3877edc6bfe 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -168,7 +168,13 @@ static void _close_odbc_conn(zend_resource *rsrc) SQLFreeEnv(conn->henv); } efree(conn); - ODBCG(num_links)--; + /* See https://github.com/php/php-src/issues/12974 why we need to check the if */ +#ifdef ZTS + if (odbc_module_entry.module_started) +#endif + { + ODBCG(num_links)--; + } } /* }}} */ diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index cf0ffcfd88284..8b8a0b5520bc8 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -315,8 +315,14 @@ static void _close_pgsql_plink(zend_resource *rsrc) PQclear(res); } PQfinish(link); - PGG(num_persistent)--; - PGG(num_links)--; + /* See https://github.com/php/php-src/issues/12974 why we need to check the if */ +#ifdef ZTS + if (pgsql_module_entry.module_started) +#endif + { + PGG(num_persistent)--; + PGG(num_links)--; + } rsrc->ptr = NULL; }