public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>, Roland McGrath <roland@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Prevent people shooting themselves in the foot with MALLOC_CHECK_=
Date: Mon, 24 Apr 2006 09:07:00 -0000	[thread overview]
Message-ID: <20060424090733.GC4651@sunsite.mff.cuni.cz> (raw)

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

Hi!

If malloc.c didn't try to special case MALLOC_CHECK_= (empty string in
the env var), I'd say why bother, but as it does, it probably doesn't
hurt to handle it gracefully.

ATM apps segfault, because in that case mallopt (M_CHECK_ACTION, something)
is not called, but __malloc_check_init is.  But in that case
malloc_consolidate has not been called and we die later on.

I'm attaching 2 patches, one which handles MALLOC_CHECK_= as if
MALLOC_CHECK_=3 was given (3 stands for DEFAULT_CHECK_ACTION here),
the other ignores MALLOC_CHECK_ var completely if it contains an empty
string.

	Jakub

[-- Attachment #2: X --]
[-- Type: text/plain, Size: 573 bytes --]

2006-04-24  Jakub Jelinek  <jakub@redhat.com>

	* malloc/arena.c (ptmalloc_init): Call mALLOPt with
	DEFAULT_CHECK_ACTION if MALLOC_CHECK_ env var contains an empty
	string.

--- libc/malloc/arena.c	6 Mar 2006 06:18:35 -0000	1.20
+++ libc/malloc/arena.c	24 Apr 2006 08:54:16 -0000
@@ -552,7 +552,7 @@ ptmalloc_init (void)
   s = getenv("MALLOC_CHECK_");
 #endif
   if(s) {
-    if(s[0]) mALLOPt(M_CHECK_ACTION, (int)(s[0] - '0'));
+    mALLOPt(M_CHECK_ACTION, s[0] ? (int)(s[0] - '0') : DEFAULT_CHECK_ACTION);
     if (check_action != 0)
       __malloc_check_init();
   }

[-- Attachment #3: Y --]
[-- Type: text/plain, Size: 560 bytes --]

2006-04-24  Jakub Jelinek  <jakub@redhat.com>

	* malloc/arena.c (ptmalloc_init): Don't call __malloc_check_init
	if MALLOC_CHECK_ env var contains an empty string.

--- libc/malloc/arena.c	6 Mar 2006 06:18:35 -0000	1.20
+++ libc/malloc/arena.c	24 Apr 2006 08:55:04 -0000
@@ -551,8 +551,8 @@ ptmalloc_init (void)
     }
   s = getenv("MALLOC_CHECK_");
 #endif
-  if(s) {
-    if(s[0]) mALLOPt(M_CHECK_ACTION, (int)(s[0] - '0'));
+  if(s && s[0]) {
+    mALLOPt(M_CHECK_ACTION, (int)(s[0] - '0'));
     if (check_action != 0)
       __malloc_check_init();
   }

             reply	other threads:[~2006-04-24  9:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-24  9:07 Jakub Jelinek [this message]
2006-04-24 17:25 ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060424090733.GC4651@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    --cc=roland@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).