summaryrefslogtreecommitdiff
path: root/libc/malloc_debug/malloc_debug.cpp
diff options
context:
space:
mode:
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 c030d5429..d2679ca4c 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;
+
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
@@ -287,6 +293,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());
}