[PATCH] Fix malloc_trim [BZ#779]
Jakub Jelinek
jakub@redhat.com
Tue Mar 15 12:38:00 GMT 2005
Hi!
malloc_trim will crash if it is the first malloc related function called
after program startup.
I have looked at other functions that lack this, and the only other public
ones that don't call ptmalloc_init are free and malloc_usable_size.
But they return immediately if passed NULL as argument, and for non-NULL
argument a non-buggy program can't call them without calling one of the
allocation functions first (that will call ptmalloc_init). So I think
this is sufficient.
2005-03-15 Jakub Jelinek <jakub@redhat.com>
[BZ #779]
* malloc/malloc.c (public_mTRIm): Initialize malloc if not yet
initialized.
--- libc/malloc/malloc.c.jj 2005-03-11 18:26:38.000000000 +0100
+++ libc/malloc/malloc.c 2005-03-15 13:12:35.373862631 +0100
@@ -3774,6 +3774,8 @@ public_mTRIm(size_t s)
{
int result;
+ if(__malloc_initialized < 0)
+ ptmalloc_init ();
(void)mutex_lock(&main_arena.mutex);
result = mTRIm(s);
(void)mutex_unlock(&main_arena.mutex);
Jakub
More information about the Libc-hacker
mailing list