This is the mail archive of the libc-hacker@sourceware.org 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 libmemusage.so


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


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