mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
* Make the memory leak reporting code much better with repeats
* Remove useless variables
This commit is contained in:
parent
6ec7163796
commit
98b6ddda90
3 changed files with 25 additions and 27 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue