From 617c647b8ef562ace589a11a15eb460e6db71f2a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Aug 2013 13:20:43 -0700 Subject: 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 Reviewed-by: "Stefan (metze) Metzmacher" Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Wed Aug 28 02:44:17 CEST 2013 on sn-devel-104 --- lib/talloc/talloc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') 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; -- cgit