cvs: ZendEngine2 / zend_alloc.c zend_alloc.h

From: Date: Tue, 25 May 2004 08:33:11 +0000
Subject: cvs: ZendEngine2 / zend_alloc.c zend_alloc.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-2659@lists.php.net to get a copy of this message
andi Tue May 25 04:33:11 2004 EDT Modified files: /ZendEngine2 zend_alloc.c zend_alloc.h Log: - Fix memory leak in mem cache in conjunction with Zend MM. How come no one - noticed this? :) http://cvs.php.net/diff.php/ZendEngine2/zend_alloc.c?r1=1.131&r2=1.132&ty=u Index: ZendEngine2/zend_alloc.c diff -u ZendEngine2/zend_alloc.c:1.131 ZendEngine2/zend_alloc.c:1.132 --- ZendEngine2/zend_alloc.c:1.131 Mon May 10 08:17:25 2004 +++ ZendEngine2/zend_alloc.c Tue May 25 04:33:11 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_alloc.c,v 1.131 2004/05/10 12:17:25 sesser Exp $ */ +/* $Id: zend_alloc.c,v 1.132 2004/05/25 08:33:11 andi Exp $ */ #include "zend.h" #include "zend_alloc.h" @@ -468,7 +468,7 @@ } -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_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 @@ } #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 @@ 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 @@ #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; } http://cvs.php.net/diff.php/ZendEngine2/zend_alloc.h?r1=1.49&r2=1.50&ty=u Index: ZendEngine2/zend_alloc.h diff -u ZendEngine2/zend_alloc.h:1.49 ZendEngine2/zend_alloc.h:1.50 --- ZendEngine2/zend_alloc.h:1.49 Thu Jan 8 12:31:47 2004 +++ ZendEngine2/zend_alloc.h Tue May 25 04:33:11 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_alloc.h,v 1.49 2004/01/08 17:31:47 sniper Exp $ */ +/* $Id: zend_alloc.h,v 1.50 2004/05/25 08:33:11 andi Exp $ */ #ifndef ZEND_ALLOC_H #define ZEND_ALLOC_H @@ -126,7 +126,7 @@ 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);

« previous php.zend-engine.cvs (#2659) next »