Index: lib/scudo/scudo_allocator.cpp =================================================================== --- lib/scudo/scudo_allocator.cpp +++ lib/scudo/scudo_allocator.cpp @@ -620,6 +620,11 @@ BackendAllocator.getStats(stats); return stats[StatType]; } + + void *handleBadRequest() { + initThreadMaybe(); + return FailureHandler::OnBadRequest(); + } }; static ScudoAllocator Instance(LINKER_INITIALIZED); @@ -677,7 +682,7 @@ uptr PageSize = GetPageSizeCached(); if (UNLIKELY(CheckForPvallocOverflow(Size, PageSize))) { errno = errno_ENOMEM; - return ScudoAllocator::FailureHandler::OnBadRequest(); + return Instance.handleBadRequest(); } // pvalloc(0) should allocate one page. Size = Size ? RoundUpTo(Size, PageSize) : PageSize; @@ -687,14 +692,14 @@ void *scudoMemalign(uptr Alignment, uptr Size) { if (UNLIKELY(!IsPowerOfTwo(Alignment))) { errno = errno_EINVAL; - return ScudoAllocator::FailureHandler::OnBadRequest(); + return Instance.handleBadRequest(); } return SetErrnoOnNull(Instance.allocate(Size, Alignment, FromMemalign)); } int scudoPosixMemalign(void **MemPtr, uptr Alignment, uptr Size) { if (UNLIKELY(!CheckPosixMemalignAlignment(Alignment))) { - ScudoAllocator::FailureHandler::OnBadRequest(); + Instance.handleBadRequest(); return errno_EINVAL; } void *Ptr = Instance.allocate(Size, Alignment, FromMemalign); @@ -707,7 +712,7 @@ void *scudoAlignedAlloc(uptr Alignment, uptr Size) { if (UNLIKELY(!CheckAlignedAllocAlignmentAndSize(Alignment, Size))) { errno = errno_EINVAL; - return ScudoAllocator::FailureHandler::OnBadRequest(); + return Instance.handleBadRequest(); } return SetErrnoOnNull(Instance.allocate(Size, Alignment, FromMalloc)); } Index: test/scudo/memalign.cpp =================================================================== --- test/scudo/memalign.cpp +++ test/scudo/memalign.cpp @@ -1,6 +1,7 @@ // RUN: %clang_scudo %s -o %t -// RUN: %run %t valid 2>&1 -// RUN: %run %t invalid 2>&1 +// RUN: %run %t valid 2>&1 +// RUN: not %run %t invalid 2>&1 +// RUN: SCUDO_OPTIONS=allocator_may_return_null=1 %run %t invalid 2>&1 // Tests that the various aligned allocation functions work as intended. Also // tests for the condition where the alignment is not a power of 2. Index: test/scudo/valloc.cpp =================================================================== --- test/scudo/valloc.cpp +++ test/scudo/valloc.cpp @@ -1,6 +1,7 @@ // RUN: %clang_scudo %s -o %t -// RUN: %run %t valid 2>&1 -// RUN: %run %t invalid 2>&1 +// RUN: %run %t valid 2>&1 +// RUN: not %run %t invalid 2>&1 +// RUN: SCUDO_OPTIONS=allocator_may_return_null=1 %run %t invalid 2>&1 // Tests that valloc and pvalloc work as intended.