diff options
author | Stefan Metzmacher <metze@samba.org> | 2011-04-04 13:28:11 +0200 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2011-04-12 15:12:52 +0200 |
commit | fea8fc6e32b19ed59e36583b12f6e55b83da0192 (patch) | |
tree | b950fcb9bdb4c7e13e94a149ef31630caf6f5b84 | |
parent | a67532a08ed58c693b8e64722039cb4c25e75b97 (diff) | |
download | samba-fea8fc6e32b19ed59e36583b12f6e55b83da0192.tar.gz |
talloc: add TC_INVALIDATE_SHRINK_CHUNK() marco
This invalidates the unused bytes if we shrink memory.
metze
Signed-off-By: Andrew Tridgell <tridge@samba.org>
(cherry picked from commit 6126c3506d493cd4836a7539586b74faea8ca0b3)
(cherry picked from commit 31578b94db5f9517ee344260e83362c547511549)
-rw-r--r-- | lib/talloc/talloc.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index 522d60ff8f4..3ec5d85eee1 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -143,6 +143,32 @@ static struct { TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc); \ } while (0) +#define TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size) do { \ + if (unlikely(talloc_fill.enabled)) { \ + size_t _flen = (_tc)->size - (_new_size); \ + char *_fptr = TC_PTR_FROM_CHUNK(_tc); \ + _fptr += (_new_size); \ + memset(_fptr, talloc_fill.fill_value, _flen); \ + } \ +} while (0) + +#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS) +/* Mark the unused bytes not accessable */ +#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { \ + size_t _flen = (_tc)->size - (_new_size); \ + char *_fptr = TC_PTR_FROM_CHUNK(_tc); \ + _fptr += (_new_size); \ + VALGRIND_MAKE_MEM_NOACCESS(_fptr, _flen); \ +} while (0) +#else +#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { } while (0) +#endif + +#define TC_INVALIDATE_SHRINK_CHUNK(_tc, _new_size) do { \ + TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size); \ + TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size); \ +} while (0) + struct talloc_reference_handle { struct talloc_reference_handle *next, *prev; void *ptr; @@ -1282,12 +1308,14 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons if (size < tc->size) { if (pool_tc) { void *next_tc = TC_POOLMEM_NEXT_CHUNK(tc); + TC_INVALIDATE_SHRINK_CHUNK(tc, size); tc->size = size; if (next_tc == pool_tc->pool) { pool_tc->pool = TC_POOLMEM_NEXT_CHUNK(tc); } return ptr; } else if ((tc->size - size) < 1024) { + TC_INVALIDATE_SHRINK_CHUNK(tc, size); /* do not shrink if we have less than 1k to gain */ tc->size = size; return ptr; |