]> granicus.if.org Git - php/commitdiff
* Make the memory leak reporting code much better with repeats
authorZeev Suraski <zeev@php.net>
Sat, 26 Jun 1999 11:48:22 +0000 (11:48 +0000)
committerZeev Suraski <zeev@php.net>
Sat, 26 Jun 1999 11:48:22 +0000 (11:48 +0000)
* Remove useless variables

Zend/zend_alloc.c
Zend/zend_alloc.h
Zend/zend_operators.c

index 4911156c6d27ebca3b3959a2323e9074e0a4ecbc..576356420c8d25182362c3b34c5c984f63aca45d 100644 (file)
@@ -104,6 +104,7 @@ ZEND_API void *_emalloc(size_t size)
                p->filename = filename;
                p->lineno = lineno;
                p->magic = MEM_BLOCK_START_MAGIC;
+               p->reported = 0;
 #endif
                HANDLE_UNBLOCK_INTERRUPTIONS();
                p->persistent = 0;
@@ -126,6 +127,7 @@ ZEND_API void *_emalloc(size_t size)
        p->filename = filename;
        p->lineno = lineno;
        p->magic = MEM_BLOCK_START_MAGIC;
+       p->reported = 0;
        *((long *)(((char *) p) + sizeof(mem_header)+size+PLATFORM_PADDING+END_ALIGNMENT(size))) = MEM_BLOCK_END_MAGIC;
 #endif
 #if MEMORY_LIMIT
@@ -340,11 +342,8 @@ ZEND_API void start_memory_manager(void)
 ZEND_API void shutdown_memory_manager(int silent, int clean_cache)
 {
        mem_header *p, *t;
-#if ZEND_DEBUG
-       char *last_filename = NULL;
-       uint last_lineno = 0;
-       uint leak_count=0, total_bytes=0;
-       unsigned char had_leaks=0;
+#ifdef ZEND_DEBUG
+       int had_leaks=0;
 #endif
        ALS_FETCH();
 
@@ -353,25 +352,26 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache)
        while (t) {
                if (!t->cached || clean_cache) {
 #if ZEND_DEBUG
-                       if (!t->cached) {
-                               had_leaks = 1;
-                               if (last_filename != t->filename || last_lineno!=t->lineno) {
-                                       /* flush old leak */
-                                       if (leak_count>0) {
-                                               if (!silent && leak_count>1) {
-                                                       zend_message_dispatcher(ZMSG_MEMORY_LEAK_REPEATED, (void *) (long) (leak_count-1));
-                                               }
-                                               leak_count=0;
-                                               total_bytes=0;
-                                       }
-                                       last_filename = t->filename;
-                                       last_lineno = t->lineno;
-                                       if (!silent) {
-                                               zend_message_dispatcher(ZMSG_MEMORY_LEAK_DETECTED, t);
+                       if (!t->cached && !t->reported) {
+                               mem_header *iterator;
+                               int total_leak=0, total_leak_count=0;
+
+                               had_leaks=1;
+                               if (!silent) {
+                                       zend_message_dispatcher(ZMSG_MEMORY_LEAK_DETECTED, t);
+                               }
+                               t->reported = 1;
+                               for (iterator=t->pNext; iterator; iterator=iterator->pNext) {
+                                       if (iterator->filename==t->filename
+                                               && iterator->lineno==t->lineno) {
+                                               total_leak += iterator->size;
+                                               total_leak_count++;
+                                               iterator->reported = 1;
                                        }
                                }
-                               leak_count++;
-                               total_bytes += t->size;
+                               if (!silent && total_leak_count>0) {
+                                       zend_message_dispatcher(ZMSG_MEMORY_LEAK_REPEATED, (void *) (long) (total_leak_count));
+                               }
                        }
 #endif
                        p = t->pNext;
@@ -382,10 +382,8 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache)
                        t = t->pNext;
                }
        }
-#if ZEND_DEBUG
-       if (!silent && leak_count>1) {
-               zend_message_dispatcher(ZMSG_MEMORY_LEAK_REPEATED, (void *) (long) (leak_count-1));
-       }
+
+#ifdef ZEND_DEBUG
        if (had_leaks) {
                ELS_FETCH();
 
index 2c3b074cdd2d21cf795ae7b0ff65f2c43736c0ce..2b847be488d17190bbcdb80281ec1b11ba016b00 100644 (file)
@@ -29,6 +29,7 @@ typedef struct _mem_header {
        long magic;
        char *filename;
        uint lineno;
+       int reported;
 #endif
     struct _mem_header *pNext;
     struct _mem_header *pLast;
index 4dc7d4c337ff6a71000842db5be13edf3a60202a..af0124ac5bae51c5827fb1b7fca29413e559a225 100644 (file)
@@ -811,7 +811,6 @@ ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2)
 ZEND_API int concat_function(zval *result, zval *op1, zval *op2)
 {
        zval op1_copy, op2_copy;
-       zval *orig_op1=op1, *orig_op2=op2;
        int use_copy1, use_copy2;