talloc: add TC_UNDEFINE_GROW_CHUNK() marco
authorStefan Metzmacher <metze@samba.org>
Mon, 4 Apr 2011 11:29:47 +0000 (13:29 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 8 Apr 2011 07:28:10 +0000 (09:28 +0200)
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
lib/talloc/talloc.c

index 3ec5d85eee177c20e9b6371c77ba1bd1c890e8f2..d1c88a247d36657f8f6441647017437b88bee21d 100644 (file)
@@ -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);