Commit 3a23bff3 authored by marko's avatar marko

branches/zip: Add Valgrind instrumentation to the InnoDB memory management

functions.

ut_malloc_low(): Flag the block with UNIV_MEM_ALLOC().  Do not flag the
block with UNIV_MEM_FREE() in ut_free(), because it would cause bogus
Valgrind warnings in the underlying memory allocator.

mem_pool_create(): Flag the data area with UNIV_MEM_FREE().

mem_pool_fill_free_list(): Flag the area header with UNIV_MEM_ALLOC().

mem_area_alloc(): Flag the data area with UNIV_MEM_ALLOC().

mem_area_free(): Flag the data area with UNIV_MEM_FREE().

mem_heap_alloc(): Flag the buffer with UNIV_MEM_ALLOC().

mem_heap_block_free(): Flag the block with UNIV_MEM_FREE().

mem_heap_free_top(): Flag the block with UNIV_MEM_FREE().
parent 6e8da36b
...@@ -164,6 +164,8 @@ mem_heap_alloc( ...@@ -164,6 +164,8 @@ mem_heap_alloc(
mem_block_set_free(block, free + MEM_SPACE_NEEDED(n)); mem_block_set_free(block, free + MEM_SPACE_NEEDED(n));
#ifdef UNIV_MEM_DEBUG #ifdef UNIV_MEM_DEBUG
UNIV_MEM_ALLOC(buf,
n + MEM_FIELD_HEADER_SIZE + MEM_FIELD_TRAILER_SIZE);
/* In the debug version write debugging info to the field */ /* In the debug version write debugging info to the field */
mem_field_init((byte*)buf, n); mem_field_init((byte*)buf, n);
...@@ -174,8 +176,10 @@ mem_heap_alloc( ...@@ -174,8 +176,10 @@ mem_heap_alloc(
#endif #endif
#ifdef UNIV_SET_MEM_TO_ZERO #ifdef UNIV_SET_MEM_TO_ZERO
UNIV_MEM_ALLOC(buf, n);
memset(buf, '\0', n); memset(buf, '\0', n);
#endif #endif
UNIV_MEM_ALLOC(buf, n);
return(buf); return(buf);
} }
...@@ -366,6 +370,8 @@ mem_heap_free_top( ...@@ -366,6 +370,8 @@ mem_heap_free_top(
if ((heap != block) && (mem_block_get_free(block) if ((heap != block) && (mem_block_get_free(block)
== mem_block_get_start(block))) { == mem_block_get_start(block))) {
mem_heap_block_free(heap, block); mem_heap_block_free(heap, block);
} else {
UNIV_MEM_FREE((byte*) block + mem_block_get_free(block), n);
} }
} }
......
...@@ -506,6 +506,7 @@ mem_heap_block_free( ...@@ -506,6 +506,7 @@ mem_heap_block_free(
mem_erase_buf((byte*)block, len); mem_erase_buf((byte*)block, len);
#endif #endif
UNIV_MEM_FREE(block, len);
if (type == MEM_HEAP_DYNAMIC) { if (type == MEM_HEAP_DYNAMIC) {
......
...@@ -229,6 +229,8 @@ mem_pool_create( ...@@ -229,6 +229,8 @@ mem_pool_create(
mem_area_set_size(area, ut_2_exp(i)); mem_area_set_size(area, ut_2_exp(i));
mem_area_set_free(area, TRUE); mem_area_set_free(area, TRUE);
UNIV_MEM_FREE(MEM_AREA_EXTRA_SIZE + (byte*) area,
ut_2_exp(i) - MEM_AREA_EXTRA_SIZE);
UT_LIST_ADD_FIRST(free_list, pool->free_list[i], area); UT_LIST_ADD_FIRST(free_list, pool->free_list[i], area);
...@@ -259,7 +261,7 @@ mem_pool_fill_free_list( ...@@ -259,7 +261,7 @@ mem_pool_fill_free_list(
ut_ad(mutex_own(&(pool->mutex))); ut_ad(mutex_own(&(pool->mutex)));
if (i >= 63) { if (UNIV_UNLIKELY(i >= 63)) {
/* We come here when we have run out of space in the /* We come here when we have run out of space in the
memory pool: */ memory pool: */
...@@ -291,7 +293,7 @@ mem_pool_fill_free_list( ...@@ -291,7 +293,7 @@ mem_pool_fill_free_list(
area = UT_LIST_GET_FIRST(pool->free_list[i + 1]); area = UT_LIST_GET_FIRST(pool->free_list[i + 1]);
} }
if (UT_LIST_GET_LEN(pool->free_list[i + 1]) == 0) { if (UNIV_UNLIKELY(UT_LIST_GET_LEN(pool->free_list[i + 1]) == 0)) {
mem_analyze_corruption(area); mem_analyze_corruption(area);
ut_error; ut_error;
...@@ -300,6 +302,7 @@ mem_pool_fill_free_list( ...@@ -300,6 +302,7 @@ mem_pool_fill_free_list(
UT_LIST_REMOVE(free_list, pool->free_list[i + 1], area); UT_LIST_REMOVE(free_list, pool->free_list[i + 1], area);
area2 = (mem_area_t*)(((byte*)area) + ut_2_exp(i)); area2 = (mem_area_t*)(((byte*)area) + ut_2_exp(i));
UNIV_MEM_ALLOC(area2, MEM_AREA_EXTRA_SIZE);
mem_area_set_size(area2, ut_2_exp(i)); mem_area_set_size(area2, ut_2_exp(i));
mem_area_set_free(area2, TRUE); mem_area_set_free(area2, TRUE);
...@@ -400,6 +403,8 @@ mem_area_alloc( ...@@ -400,6 +403,8 @@ mem_area_alloc(
mutex_exit(&(pool->mutex)); mutex_exit(&(pool->mutex));
ut_ad(mem_pool_validate(pool)); ut_ad(mem_pool_validate(pool));
UNIV_MEM_ALLOC(MEM_AREA_EXTRA_SIZE + (byte*)area,
ut_2_exp(n) - MEM_AREA_EXTRA_SIZE);
return((void*)(MEM_AREA_EXTRA_SIZE + ((byte*)area))); return((void*)(MEM_AREA_EXTRA_SIZE + ((byte*)area)));
} }
...@@ -482,6 +487,7 @@ mem_area_free( ...@@ -482,6 +487,7 @@ mem_area_free(
} }
size = mem_area_get_size(area); size = mem_area_get_size(area);
UNIV_MEM_FREE(ptr, size - MEM_AREA_EXTRA_SIZE);
if (size == 0) { if (size == 0) {
fprintf(stderr, fprintf(stderr,
......
...@@ -162,6 +162,8 @@ ut_malloc_low( ...@@ -162,6 +162,8 @@ ut_malloc_low(
#endif #endif
} }
UNIV_MEM_ALLOC(ret, n + sizeof(ut_mem_block_t));
((ut_mem_block_t*)ret)->size = n + sizeof(ut_mem_block_t); ((ut_mem_block_t*)ret)->size = n + sizeof(ut_mem_block_t);
((ut_mem_block_t*)ret)->magic_n = UT_MEM_MAGIC_N; ((ut_mem_block_t*)ret)->magic_n = UT_MEM_MAGIC_N;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment