This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] BZ #14545: Always check dtv before freeing dtv[-1]
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Wed, 5 Sep 2012 13:21:07 -0700
- Subject: [PATCH] BZ #14545: Always check dtv before freeing dtv[-1]
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
We should always check dtv before freeing dtv[-1], including in
libc.a, since dtv is a static array in libc.a. _dl_initial_dtv
is intialized to &static_dtv[1] so that index -1 contains the length.
Testd on Linux/x86-64. OK to install?
Thanks.
H.J.
---
ChangeLog | 7 +++++++
csu/libc-tls.c | 2 ++
elf/dl-tls.c | 2 --
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8e3667f..672f99f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2012-09-05 H.J. Lu <hongjiu.lu@intel.com>
+ [BZ #14545]
+ * csu/libc-tls.c (_dl_initial_dtv): New variable.
+ * elf/dl-tls.c (_dl_deallocate_tls): Always check dtv before
+ freeing dtv[-1].
+
+2012-09-05 H.J. Lu <hongjiu.lu@intel.com>
+
[BZ #5784]
* extra-lib.mk: Skip archive if it is in $(skip-lib.a)
diff --git a/csu/libc-tls.c b/csu/libc-tls.c
index b00a5cc..eb9c502 100644
--- a/csu/libc-tls.c
+++ b/csu/libc-tls.c
@@ -65,6 +65,8 @@ size_t _dl_tls_static_size = 2048;
size_t _dl_tls_static_used;
/* Alignment requirement of the static TLS block. */
size_t _dl_tls_static_align;
+/* Initial dtv of the main thread, not allocated with normal malloc. */
+void *_dl_initial_dtv = &static_dtv[1];
/* Generation counter for the dtv. */
size_t _dl_tls_generation;
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index 4138312..ff59e9e 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -477,9 +477,7 @@ _dl_deallocate_tls (void *tcb, bool dealloc_tcb)
free (dtv[1 + cnt].pointer.val);
/* The array starts with dtv[-1]. */
-#ifdef SHARED
if (dtv != GL(dl_initial_dtv))
-#endif
free (dtv - 1);
if (dealloc_tcb)
--
1.7.11.4