mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
- Don't keep allocated blocks in a linked list if we're in non-debug mode
- as now the memory manager takes care to nuke all leaking blocks.
This commit is contained in:
parent
ba72dbf37a
commit
1c20bf27da
3 changed files with 17 additions and 2 deletions
|
@ -172,7 +172,9 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
|
||||||
return (void *)p;
|
return (void *)p;
|
||||||
}
|
}
|
||||||
p->cached = 0;
|
p->cached = 0;
|
||||||
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||||
ADD_POINTER_TO_LIST(p);
|
ADD_POINTER_TO_LIST(p);
|
||||||
|
#endif
|
||||||
p->size = size; /* Save real size for correct cache output */
|
p->size = size; /* Save real size for correct cache output */
|
||||||
#if ZEND_DEBUG
|
#if ZEND_DEBUG
|
||||||
p->filename = __zend_filename;
|
p->filename = __zend_filename;
|
||||||
|
@ -231,7 +233,9 @@ ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HANDLE_BLOCK_INTERRUPTIONS();
|
HANDLE_BLOCK_INTERRUPTIONS();
|
||||||
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||||
REMOVE_POINTER_FROM_LIST(p);
|
REMOVE_POINTER_FROM_LIST(p);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MEMORY_LIMIT
|
#if MEMORY_LIMIT
|
||||||
AG(allocated_memory) -= SIZE;
|
AG(allocated_memory) -= SIZE;
|
||||||
|
@ -288,7 +292,9 @@ ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LIN
|
||||||
CALCULATE_REAL_SIZE_AND_CACHE_INDEX(size);
|
CALCULATE_REAL_SIZE_AND_CACHE_INDEX(size);
|
||||||
|
|
||||||
HANDLE_BLOCK_INTERRUPTIONS();
|
HANDLE_BLOCK_INTERRUPTIONS();
|
||||||
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||||
REMOVE_POINTER_FROM_LIST(p);
|
REMOVE_POINTER_FROM_LIST(p);
|
||||||
|
#endif
|
||||||
p = (zend_mem_header *) ZEND_DO_REALLOC(p, sizeof(zend_mem_header)+MEM_HEADER_PADDING+SIZE+END_MAGIC_SIZE);
|
p = (zend_mem_header *) ZEND_DO_REALLOC(p, sizeof(zend_mem_header)+MEM_HEADER_PADDING+SIZE+END_MAGIC_SIZE);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
if (!allow_failure) {
|
if (!allow_failure) {
|
||||||
|
@ -299,11 +305,15 @@ ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LIN
|
||||||
exit(1);
|
exit(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||||
ADD_POINTER_TO_LIST(orig);
|
ADD_POINTER_TO_LIST(orig);
|
||||||
|
#endif
|
||||||
HANDLE_UNBLOCK_INTERRUPTIONS();
|
HANDLE_UNBLOCK_INTERRUPTIONS();
|
||||||
return (void *)NULL;
|
return (void *)NULL;
|
||||||
}
|
}
|
||||||
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||||
ADD_POINTER_TO_LIST(p);
|
ADD_POINTER_TO_LIST(p);
|
||||||
|
#endif
|
||||||
#if ZEND_DEBUG
|
#if ZEND_DEBUG
|
||||||
p->filename = __zend_filename;
|
p->filename = __zend_filename;
|
||||||
p->lineno = __zend_lineno;
|
p->lineno = __zend_lineno;
|
||||||
|
@ -461,7 +471,7 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||||
for (fci=0; fci<MAX_FAST_CACHE_TYPES; fci++) {
|
for (fci=0; fci<MAX_FAST_CACHE_TYPES; fci++) {
|
||||||
fast_cache_list_entry = AG(fast_cache_list_head)[fci];
|
fast_cache_list_entry = AG(fast_cache_list_head)[fci];
|
||||||
while (fast_cache_list_entry) {
|
while (fast_cache_list_entry) {
|
||||||
|
@ -579,6 +589,7 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache TSRMLS_DC)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "../TSRM/TSRM.h"
|
#include "../TSRM/TSRM.h"
|
||||||
#include "zend_globals_macros.h"
|
#include "zend_globals_macros.h"
|
||||||
|
|
||||||
|
#include "zend_mm.h"
|
||||||
|
|
||||||
#define MEM_BLOCK_START_MAGIC 0x7312F8DCL
|
#define MEM_BLOCK_START_MAGIC 0x7312F8DCL
|
||||||
#define MEM_BLOCK_END_MAGIC 0x2A8FCC84L
|
#define MEM_BLOCK_END_MAGIC 0x2A8FCC84L
|
||||||
#define MEM_BLOCK_FREED_MAGIC 0x99954317L
|
#define MEM_BLOCK_FREED_MAGIC 0x99954317L
|
||||||
|
@ -43,8 +45,10 @@ typedef struct _zend_mem_header {
|
||||||
THREAD_T thread_id;
|
THREAD_T thread_id;
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||||
struct _zend_mem_header *pNext;
|
struct _zend_mem_header *pNext;
|
||||||
struct _zend_mem_header *pLast;
|
struct _zend_mem_header *pLast;
|
||||||
|
#endif
|
||||||
unsigned int size:31;
|
unsigned int size:31;
|
||||||
unsigned int cached:1;
|
unsigned int cached:1;
|
||||||
} zend_mem_header;
|
} zend_mem_header;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "zend.h"
|
#include "zend_types.h"
|
||||||
|
|
||||||
/* Define this to enable Zend MM */
|
/* Define this to enable Zend MM */
|
||||||
#undef ZEND_MM
|
#undef ZEND_MM
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue