This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] malloc: Perform full initialization before __malloc_check_init
- From: Florian Weimer <fweimer at redhat dot com>
- To: DJ Delorie <dj at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 26 Sep 2017 15:05:00 +0200
- Subject: Re: [PATCH] malloc: Perform full initialization before __malloc_check_init
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2642A7E442
- References: <xningdnprh.fsf@greed.delorie.com>
On 09/20/2017 09:17 PM, DJ Delorie wrote:
fweimer@redhat.com (Florian Weimer) writes:
+ /* Perform full initialization. */
+ malloc_consolidate (&main_arena);
I'd like this comment to have more of a "why" component, so that future
readers understand why we're "consolidating" in an initialization
function, but otherwise the patch looks good to me. Perhaps this?
/* Call this once to initialize the arenas as a side-effect. */
There is just one arena at this point, and maybe we should explain the
concrete reason why this is needed. What about the attached patch?
Thanks,
Florian
Previously, initialization was implicitly performed by mallopt,
but commit ac3ed168d0c0b2b702319ac0db72c9b475a8c72e (malloc:
Remove check_action variable) removed the mallopt call.
2017-09-26 Florian Weimer <fweimer@redhat.com>
[BZ #22159]
* malloc/arena.c [!HAVE_TUNABLES] (ptmalloc_init): Call
malloc_consolidate before __malloc_check_init.
diff --git a/malloc/arena.c b/malloc/arena.c
index 9e5a62d260..ff6b6370a5 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -322,14 +322,14 @@ ptmalloc_init (void)
TUNABLE_GET (mmap_max, int32_t, TUNABLE_CALLBACK (set_mmaps_max));
TUNABLE_GET (arena_max, size_t, TUNABLE_CALLBACK (set_arena_max));
TUNABLE_GET (arena_test, size_t, TUNABLE_CALLBACK (set_arena_test));
-#if USE_TCACHE
+# if USE_TCACHE
TUNABLE_GET (tcache_max, size_t, TUNABLE_CALLBACK (set_tcache_max));
TUNABLE_GET (tcache_count, size_t, TUNABLE_CALLBACK (set_tcache_count));
TUNABLE_GET (tcache_unsorted_limit, size_t,
TUNABLE_CALLBACK (set_tcache_unsorted_limit));
-#endif
+# endif
__libc_lock_unlock (main_arena.mutex);
-#else
+#else /* !HAVE_TUNABLES */
const char *s = NULL;
if (__glibc_likely (_environ != NULL))
{
@@ -393,8 +393,13 @@ ptmalloc_init (void)
}
}
if (s && s[0] != '\0' && s[0] != '0')
- __malloc_check_init ();
-#endif
+ {
+ /* Heap checking requires a valid top chunk, so perform full
+ initialization here. */
+ malloc_consolidate (&main_arena);
+ __malloc_check_init ();
+ }
+#endif /* !HAVE_TUNABLES */
#if HAVE_MALLOC_INIT_HOOK
void (*hook) (void) = atomic_forced_read (__malloc_initialize_hook);