From de0d354736a08e2218d37dfe70314f81cf765839 Mon Sep 17 00:00:00 2001 From: Andi Gutmans Date: Sun, 2 Apr 2000 20:26:06 +0000 Subject: [PATCH] - Create dtor function --- main/SAPI.c | 3 +++ main/php_virtual_cwd.c | 17 +++++++++++++++-- main/php_virtual_cwd.h | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/main/SAPI.c b/main/SAPI.c index 85892b3501..3f29c97769 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -92,6 +92,9 @@ SAPI_API void sapi_startup(sapi_module_struct *sf) SAPI_API void sapi_shutdown(void) { reentrancy_shutdown(); +#ifdef VIRTUAL_DIR + virtual_cwd_shutdown(); +#endif php_global_shutdown_internal_extensions(); zend_hash_destroy(&known_post_content_types); } diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c index 470c28a2b3..8a2ecd0278 100644 --- a/main/php_virtual_cwd.c +++ b/main/php_virtual_cwd.c @@ -123,6 +123,11 @@ static void cwd_globals_ctor(zend_cwd_globals *cwd_globals) CWD_STATE_COPY(&cwd_globals->cwd, &main_cwd_state); } +static void cwd_globals_dtor(zend_cwd_globals *cwd_globals) +{ + CWD_STATE_FREE(&cwd_globals->cwd); +} + void virtual_cwd_startup() { char cwd[1024]; /* Should probably use system define here */ @@ -135,7 +140,15 @@ void virtual_cwd_startup() main_cwd_state.cwd = strdup(cwd); main_cwd_state.cwd_length = strlen(cwd); - ZEND_INIT_MODULE_GLOBALS(cwd, cwd_globals_ctor, NULL); + ZEND_INIT_MODULE_GLOBALS(cwd, cwd_globals_ctor, cwd_globals_dtor); +} + +void virtual_cwd_shutdown() +{ +#ifndef ZTS + cwd_globals_dtor(&cwd_globals); +#endif + free(main_cwd_state.cwd); /* Don't use CWD_STATE_FREE because the non global states will probably use emalloc()/efree() */ } char *virtual_getcwd_ex(int *length) @@ -291,7 +304,7 @@ int virtual_chdir_file(char *path) int length = strlen(path); if (length == 0) { - return 1; /* Can't CD to empty string */ + return 1; /* Can't cd to empty string */ } while(--length >= 0 && !IS_SLASH(path[length])) { } diff --git a/main/php_virtual_cwd.h b/main/php_virtual_cwd.h index e98bb5344c..24fe7e7c8b 100644 --- a/main/php_virtual_cwd.h +++ b/main/php_virtual_cwd.h @@ -22,6 +22,7 @@ typedef struct _cwd_state { typedef int (*verify_path_func)(const cwd_state *); void virtual_cwd_startup(); +void virtual_cwd_shutdown(); char *virtual_getcwd_ex(int *length); char *virtual_getcwd(char *buf, size_t size); int virtual_chdir(char *path); -- 2.40.0