From: Stefan Esser Date: Mon, 10 May 2004 12:17:25 +0000 (+0000) Subject: Checking MEMORY_LIMIT before doing emalloc/erealloc solves several ugly problems. X-Git-Tag: RELEASE_0_1~241 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2224276a1303822e098c1e8ffc2ce141a8e709ea;p=php Checking MEMORY_LIMIT before doing emalloc/erealloc solves several ugly problems. --- diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index e38b1bfc4f..0cce872269 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -164,6 +164,12 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) if (CACHE_INDEX AG(allocated_memory_peak)) { + AG(allocated_memory_peak) = AG(allocated_memory); + } #endif p = (zend_mem_header *) ZEND_DO_MALLOC(sizeof(zend_mem_header) + MEM_HEADER_PADDING + SIZE + END_MAGIC_SIZE); #if !ZEND_DISABLE_MEMORY_CACHE @@ -199,12 +205,6 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) # endif memcpy((((char *) p) + sizeof(zend_mem_header) + MEM_HEADER_PADDING + size), &mem_block_end_magic, sizeof(long)); #endif -#if MEMORY_LIMIT - CHECK_MEMORY_LIMIT(size, SIZE); - if (AG(allocated_memory) > AG(allocated_memory_peak)) { - AG(allocated_memory_peak) = AG(allocated_memory); - } -#endif HANDLE_UNBLOCK_INTERRUPTIONS(); return (void *)((char *)p + sizeof(zend_mem_header) + MEM_HEADER_PADDING); @@ -331,6 +331,12 @@ ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LIN CALCULATE_REAL_SIZE_AND_CACHE_INDEX(size); HANDLE_BLOCK_INTERRUPTIONS(); +#if MEMORY_LIMIT + CHECK_MEMORY_LIMIT(size - p->size, SIZE - REAL_SIZE(p->size)); + if (AG(allocated_memory) > AG(allocated_memory_peak)) { + AG(allocated_memory_peak) = AG(allocated_memory); + } +#endif #if ZEND_DEBUG || !defined(ZEND_MM) REMOVE_POINTER_FROM_LIST(p); #endif @@ -359,12 +365,6 @@ ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LIN p->magic = MEM_BLOCK_START_MAGIC; memcpy((((char *) p) + sizeof(zend_mem_header) + MEM_HEADER_PADDING + size), &mem_block_end_magic, sizeof(long)); #endif -#if MEMORY_LIMIT - CHECK_MEMORY_LIMIT(size - p->size, SIZE - REAL_SIZE(p->size)); - if (AG(allocated_memory) > AG(allocated_memory_peak)) { - AG(allocated_memory_peak) = AG(allocated_memory); - } -#endif p->size = size;