]> granicus.if.org Git - php/commitdiff
Fixed memory leaks in ZTS mode.
authorDmitry Stogov <dmitry@php.net>
Mon, 17 Jul 2006 07:20:12 +0000 (07:20 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 17 Jul 2006 07:20:12 +0000 (07:20 +0000)
main/main.c

index e2e8e376109091ac6481e3c0c348b6e41246f28e..4648f5ad6e9ac9de7c75f9f5bb3ed74afa7741b7 100644 (file)
@@ -1350,6 +1350,25 @@ static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC)
 /* }}} */
 #endif
 
+/* {{{ core_globals_dtor
+ */
+static void core_globals_dtor(php_core_globals *core_globals TSRMLS_DC)
+{
+       if (core_globals->last_error_message) {
+               free(core_globals->last_error_message);
+       }
+       if (core_globals->last_error_file) {
+               free(core_globals->last_error_file);
+       }
+       if (core_globals->disable_functions) {
+               free(core_globals->disable_functions);
+       }
+       if (core_globals->disable_classes) {
+               free(core_globals->disable_classes);
+       }
+}
+/* }}} */
+
 /* {{{ php_register_extensions
  */
 int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC)
@@ -1436,7 +1455,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
 
 #ifdef ZTS
        executor_globals = ts_resource(executor_globals_id);
-       ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, NULL);
+       ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
        core_globals = ts_resource(core_globals_id);
 #ifdef PHP_WIN32
        ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, NULL);
@@ -1639,23 +1658,13 @@ void php_module_shutdown(TSRMLS_D)
 #ifndef ZTS
        zend_ini_shutdown(TSRMLS_C);
        shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
+       core_globals_dtor(&core_globals TSRMLS_CC);
 #else
        zend_ini_global_shutdown(TSRMLS_C);
+       ts_free_id(core_globals_id);    
 #endif
 
        module_initialized = 0;
-       if (PG(last_error_message)) {
-               free(PG(last_error_message));
-       }
-       if (PG(last_error_file)) {
-               free(PG(last_error_file));
-       }
-       if (PG(disable_functions)) {
-               free(PG(disable_functions));
-       }
-       if (PG(disable_classes)) {
-               free(PG(disable_classes));
-       }
 }
 /* }}} */