Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disable MI_DEBUG in ASAN builds
  • Loading branch information
tiran committed Aug 30, 2022
commit f27d04f85336c22604a8f227f967f5c7630f126f
28 changes: 24 additions & 4 deletions Include/internal/pycore_mimalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,31 @@
#define MI_DEBUG_FREED PYMEM_DEADBYTE
#define MI_DEBUG_PADDING PYMEM_FORBIDDENBYTE

/* ASAN builds don't use MI_DEBUG. ASAN + MI_DEBUG triggers additional
* checks, which can cause mimalloc to print warnings to stderr. The
* warnings break some tests.
*
* mi_usable_size: pointer might not point to a valid heap region:
* ...
* yes, the previous pointer ... was valid after all
*/
#if defined(__has_feature)
# if __has_feature(address_sanitizer)
# define MI_DEBUG 0
# endif
#elif defined(__GNUC__) && defined(__SANITIZE_ADDRESS__)
# define MI_DEBUG 0
#endif

/* Perform additional checks in debug builds, see mimalloc-types.h
* - enable basic and internal assertion checks with MI_DEBUG 2
* - check for double free, invalid pointer free
* - use guard pages to check for buffer overflows
*/
#ifdef Py_DEBUG
// see mimalloc-types.h
// basic and internal assertion checks
# define MI_DEBUG 2
// check for double free, buffer overflows and invalid pointer free
# ifndef MI_DEBUG
# define MI_DEBUG 2
# endif
# define MI_SECURE 4
#elif defined(PY_MIMALLOC_SECURE)
# define MI_SECURE PY_MIMALLOC_SECURE
Expand Down
15 changes: 0 additions & 15 deletions Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ _PyMem_RawFree(void *Py_UNUSED(ctx), void *ptr)

#ifdef WITH_MIMALLOC

static void
_PyMimalloc_Config(void) {
/* XXX Some options cannot be changed because
PyRuntime_Initialize() -> alloc_for_runtime()
allocates memory, which initializes mimalloc.

verbose logging breaks some tests in debug mode:
"pointer might not point to a valid heap region"
*/
mi_option_disable(mi_option_verbose);
}

static void *
_PyMimalloc_Malloc(void *ctx, size_t size)
{
Expand Down Expand Up @@ -442,9 +430,6 @@ _PyMem_SetupAllocators(PyMemAllocatorName allocator)
PyMem_SetupDebugHooks();
}

// set global mimalloc flags
_PyMimalloc_Config();

break;
}
#endif
Expand Down