>From 669a06ca9664ea31c7eb0a5550963a763642a050 Mon Sep 17 00:00:00 2001 From: eindenbom Date: Fri, 16 Apr 2010 09:59:08 +0400 Subject: [PATCH] Avoid accessing half-deallocated memory when using talloc_zfree macro. The correct memory deallocation sequence is: - clear pointer to memory first - then deallocate memory --- src/util/util.h | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/util/util.h b/src/util/util.h index db8e1ac..5cdb1b3 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -118,7 +118,11 @@ errno_t set_debug_file_from_fd(const int fd); #define FLAGS_PID_FILE 0x0004 #ifndef talloc_zfree -#define talloc_zfree(ptr) do { talloc_free(ptr); ptr = NULL; } while(0) +#define talloc_zfree(ptr) do { \ + TALLOC_CTX *_tmp_ctx = (ptr); \ + (ptr) = NULL; \ + talloc_free(_tmp_ctx); \ + } while(0) #endif #ifndef discard_const_p -- 1.6.6.1