aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/malloc_debug_common.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-01-17 18:36:06 -0800
committerElliott Hughes <enh@google.com>2013-01-18 22:20:06 -0800
commit1e980b6bc8315d00a07312b25486531247abd98c (patch)
tree539f2c0c63fca27d5eb6ba184d658bb0e11a32d9 /libc/bionic/malloc_debug_common.cpp
parente4ca88d9fa8757e4fb4056fcafa5bc15b406a2fd (diff)
downloadandroid_bionic-1e980b6bc8315d00a07312b25486531247abd98c.tar.gz
android_bionic-1e980b6bc8315d00a07312b25486531247abd98c.tar.bz2
android_bionic-1e980b6bc8315d00a07312b25486531247abd98c.zip
Fix the duplication in the debugging code.
We had two copies of the backtrace code, and two copies of the libcorkscrew /proc/pid/maps code. This patch gets us down to one. We also had hacks so we could log in the malloc debugging code. This patch pulls the non-allocating "printf" code out of the dynamic linker so everyone can share. This patch also makes the leak diagnostics easier to read, and makes it possible to paste them directly into the 'stack' tool (by using relative PCs). This patch also fixes the stdio standard stream leak that was causing a leak warning every time tf_daemon ran. Bug: 7291287 Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
Diffstat (limited to 'libc/bionic/malloc_debug_common.cpp')
-rw-r--r--libc/bionic/malloc_debug_common.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/libc/bionic/malloc_debug_common.cpp b/libc/bionic/malloc_debug_common.cpp
index 624a40e26..bba0472e3 100644
--- a/libc/bionic/malloc_debug_common.cpp
+++ b/libc/bionic/malloc_debug_common.cpp
@@ -294,8 +294,8 @@ static void* libc_malloc_impl_handle = NULL;
unsigned int malloc_double_free_backlog;
static void InitMalloc(MallocDebug* table, int debug_level, const char* prefix) {
- __libc_android_log_print(ANDROID_LOG_INFO, "libc", "%s: using libc.debug.malloc %d (%s)\n",
- __progname, debug_level, prefix);
+ __libc_format_log(ANDROID_LOG_INFO, "libc", "%s: using libc.debug.malloc %d (%s)\n",
+ __progname, debug_level, prefix);
char symbol[128];
@@ -429,7 +429,7 @@ static void malloc_init_impl() {
dlclose(libc_malloc_impl_handle);
return;
}
- if (malloc_debug_initialize()) {
+ if (malloc_debug_initialize() == -1) {
dlclose(libc_malloc_impl_handle);
return;
}
@@ -487,11 +487,19 @@ static void malloc_init_impl() {
}
static void malloc_fini_impl() {
- if (libc_malloc_impl_handle) {
+ // Our BSD stdio implementation doesn't close the standard streams, it only flushes them.
+ // And it doesn't do that until its atexit handler (_cleanup) is run, and we run first!
+ // It's great that other unclosed FILE*s show up as malloc leaks, but we need to manually
+ // clean up the standard streams ourselves.
+ fclose(stdin);
+ fclose(stdout);
+ fclose(stderr);
+
+ if (libc_malloc_impl_handle != NULL) {
MallocDebugFini malloc_debug_finalize =
reinterpret_cast<MallocDebugFini>(dlsym(libc_malloc_impl_handle,
"malloc_debug_finalize"));
- if (malloc_debug_finalize) {
+ if (malloc_debug_finalize != NULL) {
malloc_debug_finalize();
}
}