public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix libmemusage.so
Date: Thu, 02 Nov 2006 16:25:00 -0000	[thread overview]
Message-ID: <20061102162502.GC5868@sunsite.mff.cuni.cz> (raw)

Hi!

When some shared libraries have destructors that free objects allocated
earlier and those destructors are run after libmemusage.so's destructor,
the programs die on invalid pointer passed to free.
One example is e.g. any program linked against libselinux.so.1 (which
malloc's selinux_mnt in its constructor and frees it in its destructor),
like id or ls.
The problem is that libmemusage.so's malloc, free etc. substantially differ
between not_me and !not_me cases (in the former case they just pass through
to libc functions, while in the latter they allocate a header in front
of the memory chunk).  Now, in libmemusage.so's destructor we don't want
the stat info to change when printing the statistics and set not_me to true
to avoid that, but we don't restore this afterwards.
This means selinux_mnt is malloced when not_me is false (i.e. with header
in front of it), but freed when not_me is true (as if it was being allocated
without the header in front of it).

2006-11-02  Jakub Jelinek  <jakub@redhat.com>

	* malloc/memusage.c (dest): Reset not_me back to false after printing
	statistics.

--- libc/malloc/memusage.c.jj	2006-10-19 17:26:39.000000000 +0200
+++ libc/malloc/memusage.c	2006-11-02 17:14:22.000000000 +0100
@@ -887,4 +887,10 @@ dest (void)
         fputc ('=', stderr);
       fputs ("\e[0;0m\n", stderr);
     }
+
+  /* Any following malloc/free etc. calls should generate statistics again,
+     because otherwise freeing something that has been malloced before
+     this destructor (including struct header in front of it) wouldn't
+     be properly freed.  */
+  not_me = false;
 }

	Jakub

                 reply	other threads:[~2006-11-02 16:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20061102162502.GC5868@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.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).