From f3698b5cedc042825862a41cf072cf43f37be3e7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 12 May 2011 12:56:22 +0100 Subject: [PATCH 2/7] DBusMemPool: inform valgrind what we're up to If we tell valgrind what we're doing, it can give better diagnostics. --- dbus/dbus-mempool.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dbus/dbus-mempool.c b/dbus/dbus-mempool.c index 680586b..3f5e669 100644 --- a/dbus/dbus-mempool.c +++ b/dbus/dbus-mempool.c @@ -24,6 +24,7 @@ #include #include "dbus-mempool.h" #include "dbus-internals.h" +#include "dbus-valgrind-internal.h" /** * @defgroup DBusMemPool memory pools @@ -171,7 +172,9 @@ _dbus_mem_pool_new (int element_size, _dbus_assert ((pool->block_size % pool->element_size) == 0); - + + VALGRIND_CREATE_MEMPOOL (pool, 0, zero_elements) + return pool; } @@ -185,6 +188,8 @@ _dbus_mem_pool_free (DBusMemPool *pool) { DBusMemBlock *block; + VALGRIND_DESTROY_MEMPOOL (pool) + block = pool->blocks; while (block != NULL) { @@ -235,6 +240,8 @@ _dbus_mem_pool_alloc (DBusMemPool *pool) pool->blocks = block; pool->allocated_elements += 1; + VALGRIND_MEMPOOL_ALLOC (pool, (void *) &block->elements[0], + pool->element_size) return (void*) &block->elements[0]; } else @@ -254,11 +261,13 @@ _dbus_mem_pool_alloc (DBusMemPool *pool) pool->free_elements = pool->free_elements->next; + VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size) + if (pool->zero_elements) memset (element, '\0', pool->element_size); pool->allocated_elements += 1; - + return element; } else @@ -319,7 +328,8 @@ _dbus_mem_pool_alloc (DBusMemPool *pool) pool->blocks->used_so_far += pool->element_size; pool->allocated_elements += 1; - + + VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size) return element; } } @@ -337,6 +347,8 @@ dbus_bool_t _dbus_mem_pool_dealloc (DBusMemPool *pool, void *element) { + VALGRIND_MEMPOOL_FREE (pool, element) + #ifdef DBUS_BUILD_TESTS if (_dbus_disable_mem_pools ()) { @@ -380,6 +392,9 @@ _dbus_mem_pool_dealloc (DBusMemPool *pool, DBusFreedElement *freed; freed = element; + /* used for internal mempool administration */ + VALGRIND_MAKE_MEM_UNDEFINED (freed, sizeof (freed)); + freed->next = pool->free_elements; pool->free_elements = freed; -- 1.7.5.1