diff options
author | Stefan Metzmacher <metze@samba.org> | 2011-04-04 13:29:47 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2011-04-08 09:28:10 +0200 |
commit | 9c9f208598d34d700bfc2ed7302b206e863a4c9b (patch) | |
tree | 59e2e4047e1193fc741eb2e8c7cb07c8348f18ce /lib/talloc | |
parent | 6126c3506d493cd4836a7539586b74faea8ca0b3 (diff) | |
download | samba-9c9f208598d34d700bfc2ed7302b206e863a4c9b.tar.gz samba-9c9f208598d34d700bfc2ed7302b206e863a4c9b.tar.xz samba-9c9f208598d34d700bfc2ed7302b206e863a4c9b.zip |
talloc: add TC_UNDEFINE_GROW_CHUNK() marco
metze
Signed-off-By: Andrew Tridgell <tridge@samba.org>
Diffstat (limited to 'lib/talloc')
-rw-r--r-- | lib/talloc/talloc.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index 3ec5d85eee1..d1c88a247d3 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -169,6 +169,23 @@ static struct { TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size); \ } while (0) +#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_UNDEFINED) +/* Mark the new bytes as undefined */ +#define TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size) do { \ + size_t _old_used = TC_HDR_SIZE + (_tc)->size; \ + size_t _new_used = TC_HDR_SIZE + (_new_size); \ + size_t _flen = _new_used - _old_used; \ + char *_fptr = _old_used + (char *)(_tc); \ + VALGRIND_MAKE_MEM_UNDEFINED(_fptr, _flen); \ +} while (0) +#else +#define TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size) do { } while (0) +#endif + +#define TC_UNDEFINE_GROW_CHUNK(_tc, _new_size) do { \ + TC_UNDEFINE_GROW_VALGRIND_CHUNK(_tc, _new_size); \ +} while (0) + struct talloc_reference_handle { struct talloc_reference_handle *next, *prev; void *ptr; @@ -1387,6 +1404,8 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons memmove(pool_tc->pool, tc, old_used); new_ptr = pool_tc->pool; + TC_UNDEFINE_GROW_CHUNK(tc, size); + pool_tc->pool = new_chunk_size + (char *)new_ptr; goto got_new_ptr; } @@ -1395,6 +1414,7 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons } if (new_chunk_size == old_chunk_size) { + TC_UNDEFINE_GROW_CHUNK(tc, size); tc->flags &= ~TALLOC_FLAG_FREE; tc->size = size; return ptr; @@ -1409,6 +1429,7 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons space_left = TC_POOL_SPACE_LEFT(pool_tc); if (space_left >= space_needed) { + TC_UNDEFINE_GROW_CHUNK(tc, size); tc->flags &= ~TALLOC_FLAG_FREE; tc->size = size; pool_tc->pool = TC_POOLMEM_NEXT_CHUNK(tc); |