diff options
author | Iris Chang <iris.chang@mediatek.com> | 2019-02-12 14:00:59 +0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2019-02-14 17:15:03 -0800 |
commit | b34415046c91d8e4af4e748689af3cb0080e0b05 (patch) | |
tree | f69a02f5e605b2a8e0e6575804d9493b64289824 /libc/malloc_debug/tests/malloc_debug_unit_tests.cpp | |
parent | 1b82812635e35667df9d28e7416d4b02c2083dfe (diff) |
malloc debug: fix LogFreeError error log
When free_track option is enabled and malloc debug detects error in
VerifyFreedPointer flow, if freed pointer's usable_size is more than
g_debug->config().fill_on_free_bytes(), the error log is not correct.
The max. bytes printed to error message should be the max bytes to
cmp, not usable size.
Bug: 124420174
Test: build pass and test pass
Change-Id: I41f35ab3330e49e0a6ad276d405bf4f6c3f0ea92
Diffstat (limited to 'libc/malloc_debug/tests/malloc_debug_unit_tests.cpp')
-rw-r--r-- | libc/malloc_debug/tests/malloc_debug_unit_tests.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp index 44f9795bc..6da95caf5 100644 --- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp +++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp @@ -990,6 +990,35 @@ TEST_F(MallocDebugTest, free_track_multiple_thread) { ASSERT_STREQ("", getFakeLogPrint().c_str()); } +TEST_F(MallocDebugTest, free_track_pointer_modified_after_free) { + Init("free_track=4 fill_on_free=2 free_track_backtrace_num_frames=0"); + + void* pointers[5]; + for (size_t i = 0; i < sizeof(pointers) / sizeof(void*); i++) { + pointers[i] = debug_malloc(100); + ASSERT_TRUE(pointers[i] != nullptr); + memset(pointers[i], 0, 100); + } + + debug_free(pointers[0]); + + // overwrite the whole pointer, only expect errors on the fill bytes we check. + memset(pointers[0], 0x20, 100); + + for (size_t i = 1; i < sizeof(pointers) / sizeof(void*); i++) { + debug_free(pointers[i]); + } + + std::string expected_log(DIVIDER); + expected_log += android::base::StringPrintf("6 malloc_debug +++ ALLOCATION %p USED AFTER FREE\n", + pointers[0]); + expected_log += "6 malloc_debug allocation[0] = 0x20 (expected 0xef)\n"; + expected_log += "6 malloc_debug allocation[1] = 0x20 (expected 0xef)\n"; + expected_log += DIVIDER; + ASSERT_STREQ("", getFakeLogBuf().c_str()); + ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); +} + TEST_F(MallocDebugTest, get_malloc_leak_info_invalid) { Init("fill"); |