diff options
author | Jeremy Allison <jra@samba.org> | 2013-08-27 13:20:43 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2013-08-28 02:44:16 +0200 |
commit | 617c647b8ef562ace589a11a15eb460e6db71f2a (patch) | |
tree | c87636b00f0c7a110bb71838e839b5197b28c51b | |
parent | cbfc3efbfd4a3a6f3b031ce8ef375d37f2c545f3 (diff) | |
download | samba-617c647b8ef562ace589a11a15eb460e6db71f2a.tar.gz samba-617c647b8ef562ace589a11a15eb460e6db71f2a.tar.bz2 samba-617c647b8ef562ace589a11a15eb460e6db71f2a.zip |
Fix valgrind errors with memmove and talloc pools.
bin/smbtorture //127.0.0.1 local.talloc now runs with no valgrind errors.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Aug 28 02:44:17 CEST 2013 on sn-devel-104
-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 677ec0f13f..69d5a16c0a 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -1609,6 +1609,27 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons size_t old_used = TC_HDR_SIZE + tc->size; size_t new_used = TC_HDR_SIZE + size; new_ptr = start; + +#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_UNDEFINED) + { + /* + * The area from + * start -> tc may have + * been freed and thus been marked as + * VALGRIND_MEM_NOACCESS. Set it to + * VALGRIND_MEM_UNDEFINED so we can + * copy into it without valgrind errors. + * We can't just mark + * new_ptr -> new_ptr + old_used + * as this may overlap on top of tc, + * (which is why we use memmove, not + * memcpy below) hence the MIN. + */ + size_t undef_len = MIN((((char *)tc) - ((char *)new_ptr)),old_used); + VALGRIND_MAKE_MEM_UNDEFINED(new_ptr, undef_len); + } +#endif + memmove(new_ptr, tc, old_used); tc = (struct talloc_chunk *)new_ptr; |