public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix libmemusage.so
@ 2006-11-02 16:25 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2006-11-02 16:25 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-11-02 16:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-02 16:25 [PATCH] Fix libmemusage.so Jakub Jelinek

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).