summaryrefslogtreecommitdiff
path: root/libc/malloc_debug/malloc_debug.cpp
diff options
context:
space:
mode:
authorShibin George <shibing@codeaurora.org>2019-05-21 12:50:10 +0530
committerShibin George <shibing@codeaurora.org>2019-06-14 09:23:44 +0000
commitb81fee767e6e91c187f619940e300ba181f871ee (patch)
tree020b7aa264a7287be4321a762052e0e7bb441de1 /libc/malloc_debug/malloc_debug.cpp
parent98fa5f3e216bd8f9bc51665c8ac121726421fc98 (diff)
Avoid recording backtrace if alloc-size is outside range of interest
Steps: 1) setprop libc.debug.malloc.program <program name> 2) setprop libc.debug.malloc.options "backtrace leak_track" 3) setprop libc.debug.malloc.minalloctorecord <int> # defaults to 0 4) setprop libc.debug.malloc.maxalloctorecord <int> # defaults to SIZE_MAX With this, backtrace recording of only those allocations which fall within the desired range will be done. CRs-Fixed: 2471840 Change-Id: I586dfd590e429b53e7b1b237294f0298ff7b4017
Diffstat (limited to 'libc/malloc_debug/malloc_debug.cpp')
-rw-r--r--libc/malloc_debug/malloc_debug.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index 53fcead01..423363fa9 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -37,6 +37,8 @@
#include <sys/param.h>
#include <unistd.h>
+#include <sys/system_properties.h>
+
#include <mutex>
#include <vector>
@@ -62,6 +64,10 @@ DebugData* g_debug;
bool* g_zygote_child;
const MallocDispatch* g_dispatch;
+
+size_t g_min_alloc_to_record = 0;
+size_t g_max_alloc_to_record = SIZE_MAX;
+
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
@@ -280,6 +286,23 @@ bool debug_initialize(const MallocDispatch* malloc_dispatch, bool* zygote_child,
// of different error cases.
backtrace_startup();
+ char min_alloc_to_record[10];
+ if (__system_property_get("libc.debug.malloc.minalloctorecord", min_alloc_to_record)) {
+ g_min_alloc_to_record = atoi(min_alloc_to_record);
+ }
+
+ char max_alloc_to_record[10];
+ if (__system_property_get("libc.debug.malloc.maxalloctorecord", max_alloc_to_record)) {
+ g_max_alloc_to_record = atoi(max_alloc_to_record);
+ }
+
+ if (g_min_alloc_to_record > g_max_alloc_to_record) {
+ error_log("%s: min_alloc_to_record > max_alloc_to_record!,"
+ "reverting back to default limits", getprogname());
+ g_min_alloc_to_record = 0;
+ g_max_alloc_to_record = SIZE_MAX;
+ }
+
if (g_debug->config().options() & VERBOSE) {
info_log("%s: malloc debug enabled", getprogname());
}