From a09ecb2504de0f9d74521039c86e4e4412d0dfa7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Jun 2004 17:22:35 +0300 Subject: [PATCH] InnoDB bug fix: mem_realloc() didn't preserve the block contents innobase/include/mem0mem.ic: mem_realloc(): preserve the old buffer contents --- innobase/include/mem0mem.ic | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/innobase/include/mem0mem.ic b/innobase/include/mem0mem.ic index c250e6948ec..a51de5a5cf0 100644 --- a/innobase/include/mem0mem.ic +++ b/innobase/include/mem0mem.ic @@ -575,9 +575,21 @@ mem_realloc( char* file_name,/* in: file name where called */ ulint line) /* in: line where called */ { - mem_free(buf); + mem_heap_t* heap = (mem_heap_t*)((byte*)buf + - MEM_BLOCK_HEADER_SIZE - MEM_FIELD_HEADER_SIZE); + ulint size; + ut_a(heap->magic_n == MEM_BLOCK_MAGIC_N); + size = mem_block_get_len(heap); + ut_a(size > MEM_BLOCK_HEADER_SIZE + MEM_FIELD_HEADER_SIZE); + size -= MEM_BLOCK_HEADER_SIZE + MEM_FIELD_HEADER_SIZE; - return(mem_alloc_func(n, file_name, line)); + if (n > size) { + void* newbuf = memcpy(mem_alloc_func(n, file_name, line), + buf, size); + mem_free(buf); + buf = newbuf; + } + return(buf); } /**************************************************************************