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/PointerData.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/PointerData.cpp')
-rw-r--r-- | libc/malloc_debug/PointerData.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libc/malloc_debug/PointerData.cpp b/libc/malloc_debug/PointerData.cpp index 638061b11..6e9d24f56 100644 --- a/libc/malloc_debug/PointerData.cpp +++ b/libc/malloc_debug/PointerData.cpp @@ -266,12 +266,12 @@ void PointerData::LogBacktrace(size_t hash_index) { error_log(" hash_index %zu does not have matching frame data.", hash_index); } -void PointerData::LogFreeError(const FreePointerInfoType& info, size_t usable_size) { +void PointerData::LogFreeError(const FreePointerInfoType& info, size_t max_cmp_bytes) { error_log(LOG_DIVIDER); uint8_t* memory = reinterpret_cast<uint8_t*>(info.pointer); error_log("+++ ALLOCATION %p USED AFTER FREE", memory); uint8_t fill_free_value = g_debug->config().fill_free_value(); - for (size_t i = 0; i < usable_size; i++) { + for (size_t i = 0; i < max_cmp_bytes; i++) { if (memory[i] != fill_free_value) { error_log(" allocation[%zu] = 0x%02x (expected 0x%02x)", i, memory[i], fill_free_value); } @@ -314,11 +314,12 @@ void PointerData::VerifyFreedPointer(const FreePointerInfoType& info) { size_t bytes = (usable_size < g_debug->config().fill_on_free_bytes()) ? usable_size : g_debug->config().fill_on_free_bytes(); + size_t max_cmp_bytes = bytes; const uint8_t* memory = reinterpret_cast<const uint8_t*>(info.pointer); while (bytes > 0) { size_t bytes_to_cmp = (bytes < g_cmp_mem.size()) ? bytes : g_cmp_mem.size(); if (memcmp(memory, g_cmp_mem.data(), bytes_to_cmp) != 0) { - LogFreeError(info, usable_size); + LogFreeError(info, max_cmp_bytes); } bytes -= bytes_to_cmp; memory = &memory[bytes_to_cmp]; |