]> granicus.if.org Git - php/commitdiff
- Fix memory leak in mem cache in conjunction with Zend MM. How come no one
authorAndi Gutmans <andi@php.net>
Tue, 25 May 2004 08:33:11 +0000 (08:33 +0000)
committerAndi Gutmans <andi@php.net>
Tue, 25 May 2004 08:33:11 +0000 (08:33 +0000)
- noticed this? :)

Zend/zend_alloc.c
Zend/zend_alloc.h

index 0cce872269ed1032ace4bcbc59293e920b145aed..9cc9038fec540ff396c326bbae4951cabf1a67dd 100644 (file)
@@ -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;
        }
index 0e3b864d174e055b1c64b8624c1c9afefa7fbcc5..7be34569311526be5c324618b58953a5224ff0f9 100644 (file)
@@ -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);