Commit 372a2524 authored by marko's avatar marko

branches/zip: Improve Valgrind instrumentation.

UNIV_MEM_ASSERT_RW(): New macro, to check that the contents of a memory
area is defined.

UNIV_MEM_ASSERT_W(): New macro, to check that a memory area is writable.

UNIV_MEM_ASSERT_AND_FREE(): New macro, to check that the memory is
writable before declaring it free (unwritable).  This replaces UNIV_MEM_FREE()
in many places.

mem_init_buf(): Declare the memory undefined.

mem_erase_buf(): Declare the memory freed.
parent 94e707cf
......@@ -77,7 +77,7 @@ buf_buddy_add_to_free(
#ifdef UNIV_DEBUG_VALGRIND
if (b) UNIV_MEM_FREE(b, BUF_BUDDY_LOW << i);
UNIV_MEM_FREE(bpage, BUF_BUDDY_LOW << i);
UNIV_MEM_ASSERT_AND_FREE(bpage, BUF_BUDDY_LOW << i);
#endif /* UNIV_DEBUG_VALGRIND */
}
......@@ -682,7 +682,7 @@ buddy_free2:
{
buf_page_t* next = UT_LIST_GET_NEXT(list, bpage);
UNIV_MEM_FREE(bpage, BUF_BUDDY_LOW << i);
UNIV_MEM_ASSERT_AND_FREE(bpage, BUF_BUDDY_LOW << i);
bpage = next;
}
}
......
......@@ -1154,7 +1154,7 @@ buf_LRU_block_free_non_file_page(
UT_LIST_ADD_FIRST(list, buf_pool->free, (&block->page));
ut_d(block->page.in_free_list = TRUE);
UNIV_MEM_FREE(block->frame, UNIV_PAGE_SIZE);
UNIV_MEM_ASSERT_AND_FREE(block->frame, UNIV_PAGE_SIZE);
}
/**********************************************************************
......
......@@ -285,18 +285,14 @@ mem_heap_free_heap_top(
ut_ad(mem_block_get_start(block) <= mem_block_get_free(block));
/* In the debug version erase block from top up */
{
ulint len = (byte*)block + block->len - old_top;
mem_erase_buf(old_top, len);
UNIV_MEM_FREE(old_top, len);
}
mem_erase_buf(old_top, (byte*)block + block->len - old_top);
/* Update allocated memory count */
mutex_enter(&mem_hash_mutex);
mem_current_allocated_memory -= (total_size - size);
mutex_exit(&mem_hash_mutex);
#else /* UNIV_MEM_DEBUG */
UNIV_MEM_FREE(old_top, (byte*)block + block->len - old_top);
UNIV_MEM_ASSERT_AND_FREE(old_top, (byte*)block + block->len - old_top);
#endif /* UNIV_MEM_DEBUG */
/* If free == start, we may free the block if it is not the first
......@@ -377,6 +373,7 @@ mem_heap_free_top(
/* Subtract the free field of block */
mem_block_set_free(block, mem_block_get_free(block)
- MEM_SPACE_NEEDED(n));
UNIV_MEM_ASSERT_W((byte*) block + mem_block_get_free(block), n);
#ifdef UNIV_MEM_DEBUG
ut_ad(mem_block_get_start(block) <= mem_block_get_free(block));
......
......@@ -86,6 +86,7 @@ memory is read outside the allocated blocks. */
#if 0
#define UNIV_DEBUG_VALGRIND /* Enable extra
Valgrind instrumentation */
#define UNIV_MEM_DEBUG /* detect memory leaks etc */
#define UNIV_DEBUG_PRINT /* Enable the compilation of
some debug print functions */
#define UNIV_BUF_DEBUG /* Enable buffer pool
......@@ -328,6 +329,10 @@ typedef void* os_thread_ret_t;
# define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
# define UNIV_MEM_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b)
# define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b)
# define UNIV_MEM_ASSERT_RW(addr, size) \
VALGRIND_CHECK_MEM_IS_DEFINED(addr, size)
# define UNIV_MEM_ASSERT_W(addr, size) \
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size)
#else
# define UNIV_MEM_VALID(addr, size) do {} while(0)
# define UNIV_MEM_INVALID(addr, size) do {} while(0)
......@@ -335,6 +340,12 @@ typedef void* os_thread_ret_t;
# define UNIV_MEM_ALLOC(addr, size) do {} while(0)
# define UNIV_MEM_DESC(addr, size, b) do {} while(0)
# define UNIV_MEM_UNDESC(b) do {} while(0)
# define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0)
# define UNIV_MEM_ASSERT_W(addr, size) do {} while(0)
#endif
#define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \
UNIV_MEM_ASSERT_RW(addr, size); \
UNIV_MEM_FREE(addr, size); \
} while (0)
#endif
......@@ -231,6 +231,8 @@ mem_init_buf(
*ptr = 0xBE;
}
}
UNIV_MEM_INVALID(buf, n);
}
/*******************************************************************
......@@ -252,6 +254,8 @@ mem_erase_buf(
*ptr = 0xAD;
}
}
UNIV_MEM_FREE(buf, n);
}
/*******************************************************************
......
......@@ -488,8 +488,9 @@ mem_heap_block_free(
of hex 0xDE and 0xAD. */
mem_erase_buf((byte*)block, len);
#endif
UNIV_MEM_FREE(block, len);
#else /* UNIV_MEM_DEBUG */
UNIV_MEM_ASSERT_AND_FREE(block, len);
#endif /* UNIV_MEM_DEBUG */
if (type == MEM_HEAP_DYNAMIC) {
......
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