diff options
| author | Dmitry Stogov <dmitry@php.net> | 2007-03-23 07:59:26 +0000 |
|---|---|---|
| committer | Dmitry Stogov <dmitry@php.net> | 2007-03-23 07:59:26 +0000 |
| commit | 2dd2ac6d50c9091daa7bbf1e50a8e50b82e3f853 (patch) | |
| tree | 7648e29835bef5c36a2c26265fd1be75b78a993b /Zend/zend_alloc.c | |
| parent | 57a88f71d51caf1ff81e78da7f37344f4b5dd98d (diff) | |
| download | php-git-2dd2ac6d50c9091daa7bbf1e50a8e50b82e3f853.tar.gz | |
Fixed bug #40883 (mysql_query() is allocating memory incorrectly). (Tony)
Diffstat (limited to 'Zend/zend_alloc.c')
| -rw-r--r-- | Zend/zend_alloc.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 9fdc212b03..9515cd4a1a 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -1969,6 +1969,50 @@ static void *_zend_mm_realloc_int(zend_mm_heap *heap, void *p, size_t size ZEND_ return p; } +#if ZEND_MM_CACHE + if (ZEND_MM_SMALL_SIZE(true_size)) { + size_t index = ZEND_MM_BUCKET_INDEX(true_size); + + if (heap->cache[index] != NULL) { + zend_mm_free_block *best_fit; + zend_mm_free_block **cache; + +#if ZEND_MM_CACHE_STAT + heap->cache_stat[index].count--; + heap->cache_stat[index].hit++; +#endif + best_fit = heap->cache[index]; + heap->cache[index] = best_fit->prev_free_block; + ZEND_MM_CHECK_MAGIC(best_fit, MEM_BLOCK_CACHED); + ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 0); + + ptr = ZEND_MM_DATA_OF(best_fit); + +#if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION + memcpy(ptr, p, mm_block->debug.size); +#else + memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE); +#endif + + heap->cached -= true_size - orig_size; + + index = ZEND_MM_BUCKET_INDEX(orig_size); + cache = &heap->cache[index]; + + ((zend_mm_free_block*)mm_block)->prev_free_block = *cache; + *cache = (zend_mm_free_block*)mm_block; + ZEND_MM_SET_MAGIC(mm_block, MEM_BLOCK_CACHED); +#if ZEND_MM_CACHE_STAT + if (++heap->cache_stat[index].count > heap->cache_stat[index].max_count) { + heap->cache_stat[index].max_count = heap->cache_stat[index].count; + } +#endif + + return ptr; + } + } +#endif + next_block = ZEND_MM_BLOCK_AT(mm_block, orig_size); if (ZEND_MM_IS_FREE_BLOCK(next_block)) { |
