public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix malloc_trim [BZ#779]
@ 2005-03-15 12:38 Jakub Jelinek
  2005-03-19  0:19 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2005-03-15 12:38 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix malloc_trim [BZ#779]
  2005-03-15 12:38 [PATCH] Fix malloc_trim [BZ#779] Jakub Jelinek
@ 2005-03-19  0:19 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2005-03-19  0:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Roland McGrath, Glibc hackers

[-- Attachment #1: Type: text/plain, Size: 109 bytes --]

Applied.

--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-03-19  0:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-15 12:38 [PATCH] Fix malloc_trim [BZ#779] Jakub Jelinek
2005-03-19  0:19 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).