summaryrefslogtreecommitdiff
path: root/libc/bionic/malloc_debug_leak.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/bionic/malloc_debug_leak.cpp')
-rw-r--r--libc/bionic/malloc_debug_leak.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/libc/bionic/malloc_debug_leak.cpp b/libc/bionic/malloc_debug_leak.cpp
index d9824f09f..7926a1f27 100644
--- a/libc/bionic/malloc_debug_leak.cpp
+++ b/libc/bionic/malloc_debug_leak.cpp
@@ -48,6 +48,7 @@
#include "debug_stacktrace.h"
#include "malloc_debug_common.h"
+#include "malloc_debug_disable.h"
#include "private/bionic_macros.h"
#include "private/libc_logging.h"
@@ -267,6 +268,7 @@ extern "C" int fill_posix_memalign(void** memptr, size_t alignment, size_t size)
return (*memptr != NULL) ? 0 : ENOMEM;
}
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
extern "C" void* fill_pvalloc(size_t bytes) {
size_t pagesize = getpagesize();
size_t size = BIONIC_ALIGN(bytes, pagesize);
@@ -279,6 +281,7 @@ extern "C" void* fill_pvalloc(size_t bytes) {
extern "C" void* fill_valloc(size_t size) {
return fill_memalign(getpagesize(), size);
}
+#endif
// =============================================================================
// malloc leak functions
@@ -287,6 +290,10 @@ extern "C" void* fill_valloc(size_t size) {
static uint32_t MEMALIGN_GUARD = 0xA1A41520;
extern "C" void* leak_malloc(size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->malloc(bytes);
+ }
+
// allocate enough space infront of the allocation to store the pointer for
// the alloc structure. This will making free'ing the structer really fast!
@@ -319,6 +326,10 @@ extern "C" void* leak_malloc(size_t bytes) {
}
extern "C" void leak_free(void* mem) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->free(mem);
+ }
+
if (mem == NULL) {
return;
}
@@ -355,6 +366,10 @@ extern "C" void leak_free(void* mem) {
}
extern "C" void* leak_calloc(size_t n_elements, size_t elem_size) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->calloc(n_elements, elem_size);
+ }
+
// Fail on overflow - just to be safe even though this code runs only
// within the debugging C library, not the production one.
if (n_elements && SIZE_MAX / n_elements < elem_size) {
@@ -370,6 +385,10 @@ extern "C" void* leak_calloc(size_t n_elements, size_t elem_size) {
}
extern "C" void* leak_realloc(void* oldMem, size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->realloc(oldMem, bytes);
+ }
+
if (oldMem == NULL) {
return leak_malloc(bytes);
}
@@ -398,6 +417,10 @@ extern "C" void* leak_realloc(void* oldMem, size_t bytes) {
}
extern "C" void* leak_memalign(size_t alignment, size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->memalign(alignment, bytes);
+ }
+
// we can just use malloc
if (alignment <= MALLOC_ALIGNMENT) {
return leak_malloc(bytes);
@@ -439,6 +462,10 @@ extern "C" void* leak_memalign(size_t alignment, size_t bytes) {
}
extern "C" size_t leak_malloc_usable_size(const void* mem) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->malloc_usable_size(mem);
+ }
+
if (mem != NULL) {
// Check the guard to make sure it is valid.
const AllocationEntry* header = const_to_header((void*)mem);
@@ -467,6 +494,10 @@ extern "C" struct mallinfo leak_mallinfo() {
}
extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->posix_memalign(memptr, alignment, size);
+ }
+
if (!powerof2(alignment)) {
return EINVAL;
}
@@ -476,7 +507,12 @@ extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size)
return (*memptr != NULL) ? 0 : ENOMEM;
}
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
extern "C" void* leak_pvalloc(size_t bytes) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->pvalloc(bytes);
+ }
+
size_t pagesize = getpagesize();
size_t size = BIONIC_ALIGN(bytes, pagesize);
if (size < bytes) { // Overflow
@@ -486,5 +522,10 @@ extern "C" void* leak_pvalloc(size_t bytes) {
}
extern "C" void* leak_valloc(size_t size) {
+ if (DebugCallsDisabled()) {
+ return g_malloc_dispatch->valloc(size);
+ }
+
return leak_memalign(getpagesize(), size);
}
+#endif