summaryrefslogtreecommitdiff
path: root/Zend/zend_alloc.c
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>1999-06-26 11:48:22 +0000
committerZeev Suraski <zeev@php.net>1999-06-26 11:48:22 +0000
commit98b6ddda907fd4ca1c2025a049767066c740986a (patch)
tree82b152d198a20cb653d4177bf1a7c8dc048cbda1 /Zend/zend_alloc.c
parent6ec71637961fccd8bd2095b44481cf923b7fdddf (diff)
downloadphp-git-98b6ddda907fd4ca1c2025a049767066c740986a.tar.gz
* Make the memory leak reporting code much better with repeats
* Remove useless variables
Diffstat (limited to 'Zend/zend_alloc.c')
-rw-r--r--Zend/zend_alloc.c50
1 files changed, 24 insertions, 26 deletions
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();