Commit c90800e3 authored by Hans Wennborg's avatar Hans Wennborg Committed by Chromium LUCI CQ

[base] Fix -Wfree-nonheap-object warning in memory_unittest.cc

New Clang warns on calling free() on stack objects by default.

Bug: 1169073
Change-Id: I9f89e389308060b424832cfc400b2fef5c104120
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2642145
Auto-Submit: Hans Wennborg <hans@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845634}
parent c7b7c0e5
......@@ -64,6 +64,11 @@ typedef BOOL (WINAPI* HeapQueryFn) \
// test suite setup and does not need to be done again, else mach_override
// will fail.
// Wrap free() in a function to thwart Clang's -Wfree-nonheap-object warning.
static void callFree(void *ptr) {
free(ptr);
}
TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
base::allocator::InitializeAllocatorShim();
......@@ -74,11 +79,11 @@ TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
#if ARCH_CPU_64_BITS
// On 64 bit Macs, the malloc system automatically abort()s on heap corruption
// but does not output anything.
ASSERT_DEATH(free(buf), "");
ASSERT_DEATH(callFree(buf), "");
#elif defined(ADDRESS_SANITIZER)
// AddressSanitizer replaces malloc() and prints a different error message on
// heap corruption.
ASSERT_DEATH(free(buf), "attempting free on address which "
ASSERT_DEATH(callFree(buf), "attempting free on address which "
"was not malloc\\(\\)-ed");
#else
ADD_FAILURE() << "This test is not supported in this build configuration.";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment