From: Zeev Suraski Date: Sat, 26 Jun 1999 11:48:22 +0000 (+0000) Subject: * Make the memory leak reporting code much better with repeats X-Git-Tag: BEFORE_REMOVING_GC_STEP1~90 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98b6ddda907fd4ca1c2025a049767066c740986a;p=php * Make the memory leak reporting code much better with repeats * Remove useless variables --- diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 4911156c6d..576356420c 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -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(); diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h index 2c3b074cdd..2b847be488 100644 --- a/Zend/zend_alloc.h +++ b/Zend/zend_alloc.h @@ -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; diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 4dc7d4c337..af0124ac5b 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -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;