diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c index e92ddecf252..3e6bbc2ff57 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.c +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c @@ -92,24 +92,10 @@ typedef struct MemHead { #ifdef DEBUG_MEMDUPLINAME int need_free_name, pad; #endif - -#ifdef DEBUG_BACKTRACE - void *backtrace[BACKTRACE_SIZE]; - int backtrace_size; -#endif } MemHead; typedef MemHead MemHeadAligned; -#ifdef DEBUG_BACKTRACE -# if defined(__linux__) || defined(__APPLE__) -# include -// Windows is not supported yet. -//# elif defined(_MSV_VER) -//# include -# endif -#endif - typedef struct MemTail { int tag3, pad; } MemTail; @@ -366,38 +352,6 @@ void *MEM_guarded_recallocN_id(void *vmemh, size_t len, const char *str) return newp; } -#ifdef DEBUG_BACKTRACE -# if defined(__linux__) || defined(__APPLE__) -static void make_memhead_backtrace(MemHead *memh) -{ - memh->backtrace_size = backtrace(memh->backtrace, BACKTRACE_SIZE); -} - -static void print_memhead_backtrace(MemHead *memh) -{ - char **strings; - int i; - - strings = backtrace_symbols(memh->backtrace, memh->backtrace_size); - for (i = 0; i < memh->backtrace_size; i++) { - print_error(" %s\n", strings[i]); - } - - free(strings); -} -# else -static void make_memhead_backtrace(MemHead *memh) -{ - (void)memh; /* Ignored. */ -} - -static void print_memhead_backtrace(MemHead *memh) -{ - (void)memh; /* Ignored. */ -} -# endif /* defined(__linux__) || defined(__APPLE__) */ -#endif /* DEBUG_BACKTRACE */ - static void make_memhead_header(MemHead *memh, size_t len, const char *str) { MemTail *memt; @@ -414,10 +368,6 @@ static void make_memhead_header(MemHead *memh, size_t len, const char *str) memh->need_free_name = 0; #endif -#ifdef DEBUG_BACKTRACE - make_memhead_backtrace(memh); -#endif - memt = (MemTail *)(((char *)memh) + sizeof(MemHead) + len); memt->tag3 = MEMTAG3; @@ -769,7 +719,9 @@ static void MEM_guarded_printmemlist_internal(int pydict) (void *)(membl + 1)); #endif #ifdef DEBUG_BACKTRACE - print_memhead_backtrace(membl); +# ifdef WITH_ASAN + __asan_describe_address(membl); +# endif #endif } if (membl->next) { diff --git a/intern/guardedalloc/intern/mallocn_intern.h b/intern/guardedalloc/intern/mallocn_intern.h index 3f048a558a8..6ed97f6d264 100644 --- a/intern/guardedalloc/intern/mallocn_intern.h +++ b/intern/guardedalloc/intern/mallocn_intern.h @@ -72,6 +72,21 @@ size_t malloc_usable_size(void *ptr); # define MEM_INLINE static inline #endif +/* BEGIN copied from BLI_asan.h */ + +/* Clang defines this. */ +#ifndef __has_feature +# define __has_feature(x) 0 +#endif + +#if (defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)) && \ + (!defined(_MSC_VER) || _MSC_VER > 1929) /* MSVC 2019 and below doesn't ship ASAN headers. */ +# include "sanitizer/asan_interface.h" +# define WITH_ASAN +#endif + +/* END copied from BLI_asan.h */ + #define IS_POW2(a) (((a) & ((a)-1)) == 0) /* Extra padding which needs to be applied on MemHead to make it aligned. */