From 39f3745cf30efe38482ffead1c32f4e62f6fe32e Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Tue, 21 Jul 2009 15:25:23 -0700 Subject: [PATCH] Restore malloc debug. Some libc changes were preventing the initialization call from being made. The basic problem appears to be that libc_init_common.c is only built once, and it's only built for the non-debug libc. --- libc/bionic/libc_init_common.c | 9 --------- libc/bionic/libc_init_dynamic.c | 7 +++++++ libc/bionic/libc_init_static.c | 6 ++++++ libc/bionic/malloc_leak.c | 15 ++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/libc/bionic/libc_init_common.c b/libc/bionic/libc_init_common.c index c77c162c5..d78d673f0 100644 --- a/libc/bionic/libc_init_common.c +++ b/libc/bionic/libc_init_common.c @@ -52,10 +52,6 @@ unsigned int __page_shift = PAGE_SHIFT; int __system_properties_init(void); -#ifdef MALLOCK_LEAK_CHECK -void malloc_debug_init(void); -#endif - void __libc_init_common(uintptr_t *elfdata) { int argc = *elfdata; @@ -87,9 +83,4 @@ void __libc_init_common(uintptr_t *elfdata) /* setup system properties - requires environment */ __system_properties_init(); - - /* setup malloc leak checker, requires system properties */ -#if MALLOC_LEAK_CHECK - malloc_debug_init(); -#endif } diff --git a/libc/bionic/libc_init_dynamic.c b/libc/bionic/libc_init_dynamic.c index b8e10782f..b479b272f 100644 --- a/libc/bionic/libc_init_dynamic.c +++ b/libc/bionic/libc_init_dynamic.c @@ -77,6 +77,13 @@ void __libc_prenit(void) tls_area[TLS_SLOT_BIONIC_PREINIT] = NULL; __libc_init_common(elfdata); + +#ifdef MALLOC_LEAK_CHECK + /* setup malloc leak checker, requires system properties */ + extern void malloc_debug_init(void); + malloc_debug_init(); +#endif + } __noreturn void __libc_init(uintptr_t *elfdata, diff --git a/libc/bionic/libc_init_static.c b/libc/bionic/libc_init_static.c index d097b6baf..e6264bbc5 100644 --- a/libc/bionic/libc_init_static.c +++ b/libc/bionic/libc_init_static.c @@ -68,6 +68,12 @@ __noreturn void __libc_init(uintptr_t *elfdata, /* Initialize the C runtime environment */ __libc_init_common(elfdata); +#ifdef MALLOC_LEAK_CHECK + /* setup malloc leak checker, requires system properties */ + extern void malloc_debug_init(void); + malloc_debug_init(); +#endif + /* Several Linux ABIs don't pass the onexit pointer, and the ones that * do never use it. Therefore, we ignore it. */ diff --git a/libc/bionic/malloc_leak.c b/libc/bionic/malloc_leak.c index df09424b3..305f954e7 100644 --- a/libc/bionic/malloc_leak.c +++ b/libc/bionic/malloc_leak.c @@ -91,7 +91,14 @@ static pthread_mutex_t gAllocationsMutex = PTHREAD_MUTEX_INITIALIZER; static HashTable gHashTable; // ============================================================================= -// output fucntions +// log functions +// ============================================================================= + +#define debug_log(format, ...) \ + __libc_android_log_print(ANDROID_LOG_DEBUG, "malloc_leak", (format), ##__VA_ARGS__ ) + +// ============================================================================= +// output functions // ============================================================================= static int hash_entry_compare(const void* arg1, const void* arg2) @@ -257,12 +264,6 @@ struct AllocationEntry { uint32_t guard; }; -// ============================================================================= -// log funtions -// ============================================================================= - -#define debug_log(format, ...) \ - __libc_android_log_print(ANDROID_LOG_DEBUG, "malloc_leak", (format), ##__VA_ARGS__ ) // ============================================================================= // Hash Table functions -- 2.11.0