diff options
author | Christopher Ferris <cferris@google.com> | 2018-03-07 13:38:48 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-04-02 18:59:23 -0700 |
commit | 4da2503d70dc4bc1444454876e3794b69227d90d (patch) | |
tree | d904c750ebac96aee76df44baad1320c0db211a3 /libc/malloc_debug/GuardData.cpp | |
parent | a3f6f6c1b9135c90e410f5382b153db9a43a4db0 (diff) |
Refactor malloc debug.
Changes
- Refactor the code so that only guards require creating a special header
for every pointer allocated.
- Store only a single copy of every backtrace. This saves memory so that
turning on the backtrace option doesn't result in 10X memory usage.
- Added new option track_allocs that only verifies pointers are valid for
free/malloc_usable_size/realloc.
- Remove suffix from test names.
- Add the TRACK_ALLOCS options to all guard options.
- Add new option verify_pointers that is a lightweight way to verify
pointers that are passed to allocation routines.
- Do auto-formatting of the code.
- Updated documentation for all of these changes.
Bug: 74361929
Test: Ran unit tests.
Test: Ran libmemunreachable unit tests.
Test: Ran an app with backtrace enabled.
Change-Id: I3246c48ae4f9811f64622d90d0a9b4d9d818702c
Diffstat (limited to 'libc/malloc_debug/GuardData.cpp')
-rw-r--r-- | libc/malloc_debug/GuardData.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/libc/malloc_debug/GuardData.cpp b/libc/malloc_debug/GuardData.cpp index d6cef85c1..f9a2dcaa7 100644 --- a/libc/malloc_debug/GuardData.cpp +++ b/libc/malloc_debug/GuardData.cpp @@ -31,13 +31,13 @@ #include <vector> -#include "backtrace.h" #include "Config.h" +#include "DebugData.h" +#include "GuardData.h" +#include "backtrace.h" #include "debug_disable.h" #include "debug_log.h" -#include "DebugData.h" #include "malloc_debug.h" -#include "GuardData.h" GuardData::GuardData(DebugData* debug_data, int init_value, size_t num_bytes) : OptionData(debug_data) { @@ -48,8 +48,8 @@ GuardData::GuardData(DebugData* debug_data, int init_value, size_t num_bytes) void GuardData::LogFailure(const Header* header, const void* pointer, const void* data) { error_log(LOG_DIVIDER); - error_log("+++ ALLOCATION %p SIZE %zu HAS A CORRUPTED %s GUARD", pointer, - header->real_size(), GetTypeName()); + error_log("+++ ALLOCATION %p SIZE %zu HAS A CORRUPTED %s GUARD", pointer, header->size, + GetTypeName()); // Log all of the failing bytes. const uint8_t* expected = cmp_mem_.data(); @@ -70,7 +70,7 @@ void GuardData::LogFailure(const Header* header, const void* pointer, const void } FrontGuardData::FrontGuardData(DebugData* debug_data, const Config& config, size_t* offset) - : GuardData(debug_data, config.front_guard_value(), config.front_guard_bytes()) { + : GuardData(debug_data, config.front_guard_value(), config.front_guard_bytes()) { // Create a buffer for fast comparisons of the front guard. cmp_mem_.resize(config.front_guard_bytes()); memset(cmp_mem_.data(), config.front_guard_value(), cmp_mem_.size()); @@ -88,8 +88,7 @@ void FrontGuardData::LogFailure(const Header* header) { } RearGuardData::RearGuardData(DebugData* debug_data, const Config& config) - : GuardData(debug_data, config.rear_guard_value(), config.rear_guard_bytes()) { -} + : GuardData(debug_data, config.rear_guard_value(), config.rear_guard_bytes()) {} bool RearGuardData::Valid(const Header* header) { return GuardData::Valid(debug_->GetRearGuard(header)); |