This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix malloc_trim [BZ#779]


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]