diff options
author | Andi Gutmans <andi@php.net> | 2004-05-25 08:33:11 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2004-05-25 08:33:11 +0000 |
commit | db90fc4c90d5ec2d4edba507fb164d8bca17599c (patch) | |
tree | b2cf22167edeeb59d7a8b8c383d0530285d03624 | |
parent | 1e36c786ae17b97859c2bc9d9849a5f205d6cc0c (diff) | |
download | php-git-db90fc4c90d5ec2d4edba507fb164d8bca17599c.tar.gz |
- Fix memory leak in mem cache in conjunction with Zend MM. How come no one
- noticed this? :)
-rw-r--r-- | Zend/zend_alloc.c | 51 | ||||
-rw-r--r-- | Zend/zend_alloc.h | 2 |
2 files changed, 27 insertions, 26 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 0cce872269..9cc9038fec 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -468,7 +468,7 @@ ZEND_API void start_memory_manager(TSRMLS_D) } -ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC) +ZEND_API void shutdown_memory_manager(int silent, int full_shutdown TSRMLS_DC) { #if ZEND_DEBUG || !defined(ZEND_MM) zend_mem_header *p, *t; @@ -477,13 +477,33 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC) zend_uint grand_total_leaks=0; #endif +#if !ZEND_DISABLE_MEMORY_CACHE + /* Free memory cache even on partial shutdown to avoid fragmentation */ + if (1 || full_shutdown) { + unsigned int i, j; + zend_mem_header *ptr; + + for (i=1; i<MAX_CACHED_MEMORY; i++) { + for (j=0; j<AG(cache_count)[i]; j++) { + ptr = (zend_mem_header *) AG(cache)[i][j]; +# if MEMORY_LIMIT + AG(allocated_memory) -= REAL_SIZE(ptr->size); +# endif + REMOVE_POINTER_FROM_LIST(ptr); + ZEND_DO_FREE(ptr); + } + AG(cache_count)[i] = 0; + } + } +#endif /* !ZEND_DISABLE_MEMORY_CACHE */ + #if defined(ZEND_MM) && !ZEND_DEBUG - if (clean_cache) { + if (full_shutdown) { zend_mm_shutdown(&AG(mm_heap)); return; } #elif defined(ZEND_WIN32) && !ZEND_DEBUG - if (clean_cache && AG(memory_heap)) { + if (full_shutdown && AG(memory_heap)) { HeapDestroy(AG(memory_heap)); return; } @@ -506,25 +526,6 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC) } #endif /* ZEND_ENABLE_FAST_CACHE */ -#if !ZEND_DISABLE_MEMORY_CACHE && !defined(ZEND_MM) - if (1 || clean_cache) { - unsigned int i, j; - zend_mem_header *ptr; - - for (i=1; i<MAX_CACHED_MEMORY; i++) { - for (j=0; j<AG(cache_count)[i]; j++) { - ptr = (zend_mem_header *) AG(cache)[i][j]; -#if MEMORY_LIMIT - AG(allocated_memory) -= REAL_SIZE(ptr->size); -#endif - REMOVE_POINTER_FROM_LIST(ptr); - ZEND_DO_FREE(ptr); - } - AG(cache_count)[i] = 0; - } - } -#endif /* !ZEND_DISABLE_MEMORY_CACHE */ - #if ZEND_DEBUG || !defined(ZEND_MM) p = AG(head); t = AG(head); @@ -584,7 +585,7 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC) zval display_memory_cache_stats; int i, j; - if (clean_cache) { + if (full_shutdown) { /* we're shutting down completely, don't even touch the INI subsystem */ break; } @@ -622,12 +623,12 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC) #endif #if defined(ZEND_MM) && ZEND_DEBUG - if (clean_cache) { + if (full_shutdown) { zend_mm_shutdown(&AG(mm_heap)); return; } #elif defined(ZEND_WIN32) && ZEND_DEBUG - if (clean_cache && AG(memory_heap)) { + if (full_shutdown && AG(memory_heap)) { HeapDestroy(AG(memory_heap)); return; } diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h index 0e3b864d17..7be3456931 100644 --- a/Zend/zend_alloc.h +++ b/Zend/zend_alloc.h @@ -126,7 +126,7 @@ ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZE ZEND_API int zend_set_memory_limit(unsigned int memory_limit); ZEND_API void start_memory_manager(TSRMLS_D); -ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC); +ZEND_API void shutdown_memory_manager(int silent, int full_shutdown TSRMLS_DC); #if ZEND_DEBUG ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); |