Refactor the malloc_info code.
malloc_info needs to be per native allocator, but the code treated it
like a global function that doesn't depend on the native memory allocator.
Update malloc debug to dump the actual pointers that it has been tracking.
Test: bionic-unit-tests pass.
Test: malloc debug tests pass.
Test: malloc hook tests pass.
Change-Id: I3b0d4d748489dd84c16d16933479dc8b8d79013e
diff --git a/libc/bionic/malloc_common.cpp b/libc/bionic/malloc_common.cpp
index bb8ec59..edd697d 100644
--- a/libc/bionic/malloc_common.cpp
+++ b/libc/bionic/malloc_common.cpp
@@ -42,6 +42,7 @@
// write_malloc_leak_info: Writes the leak info data to a file.
#include <stdint.h>
+#include <stdio.h>
#include <private/bionic_config.h>
@@ -93,6 +94,14 @@
return Malloc(mallinfo)();
}
+extern "C" int malloc_info(int options, FILE* fp) {
+ auto dispatch_table = GetDispatchTable();
+ if (__predict_false(dispatch_table != nullptr)) {
+ return dispatch_table->malloc_info(options, fp);
+ }
+ return Malloc(malloc_info)(options, fp);
+}
+
extern "C" int mallopt(int param, int value) {
auto dispatch_table = GetDispatchTable();
if (__predict_false(dispatch_table != nullptr)) {