]> granicus.if.org Git - php/commitdiff
Give more information and save log lines in memory leak reports
authorZeev Suraski <zeev@php.net>
Sat, 22 May 1999 11:20:56 +0000 (11:20 +0000)
committerZeev Suraski <zeev@php.net>
Sat, 22 May 1999 11:20:56 +0000 (11:20 +0000)
Zend/zend.h
Zend/zend_alloc.c
Zend/zend_execute_API.c

index 2a397b9a535d2da307c32e87a76e00f338e6ee58..4318c5dd214e05c8a3f24d8c778a7e491b7e79a9 100644 (file)
@@ -221,5 +221,6 @@ extern zend_utility_values zend_uv;
 #define ZMSG_FAILED_REQUIRE_FOPEN              3L
 #define ZMSG_FAILED_HIGHLIGHT_FOPEN            4L
 #define ZMSG_MEMORY_LEAK_DETECTED              5L
+#define ZMSG_MEMORY_LEAK_REPEATED              6L
 
 #endif /* _ZEND_H */
index 1848388c70fee7094c3869c4a65dc2e3aa0f3c19..d54f00608be5c87d0a3753dbecf7c7e3875fb535 100644 (file)
@@ -340,6 +340,11 @@ 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;
+#endif
        ALS_FETCH();
 
        p=AG(head);
@@ -348,10 +353,23 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache)
                if (!t->cached || clean_cache) {
 #if ZEND_DEBUG
                        if (!t->cached) {
-                               /* does not use zend_error() *intentionally* */
-                               if (!silent) {
-                                       zend_message_dispatcher(ZMSG_MEMORY_LEAK_DETECTED, t);
+                               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 *) 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);
+                                       }
                                }
+                               leak_count++;
+                               total_bytes += t->size;
                        }
 #endif
                        p = t->pNext;
@@ -362,6 +380,11 @@ 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 *) leak_count-1);
+       }
+#endif
 }
 
 
index 180462ed2dd2d4271b127dca9c246fab78ee38ce..526b965906fbb648580981627e3c50d5f0e7d940 100644 (file)
@@ -35,16 +35,15 @@ static void (*original_sigsegv_handler)(int);
 static void zend_handle_sigsegv(int dummy)
 {
        fflush(stdout);
+       fflush(stderr);
        signal(SIGSEGV, original_sigsegv_handler);
-/*
-       printf("SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n",
+       fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n",
                        active_opline->opcode,
                        active_opline-EG(active_op_array)->opcodes,
                        get_active_function_name(),
                        zend_get_executed_filename(),
                        zend_get_executed_lineno());
        original_sigsegv_handler(dummy);
-*/
 }