diff options
author | Carlos O'Donell <carlos@redhat.com> | 2018-06-22 09:28:47 -0400 |
---|---|---|
committer | Carlos O'Donell <carlos@redhat.com> | 2018-06-29 22:39:06 -0400 |
commit | 2827ab990aefbb0e53374199b875d98f116d6390 (patch) | |
tree | 0063b4c07be87d887d4a4893b9681b9e61479e8b /dlfcn/dlerror.c | |
parent | 37d3d244e1a0ca7e7ac89b8e768e665adbb2e2d8 (diff) | |
download | glibc-2827ab990aefbb0e53374199b875d98f116d6390.zip glibc-2827ab990aefbb0e53374199b875d98f116d6390.tar.gz glibc-2827ab990aefbb0e53374199b875d98f116d6390.tar.bz2 |
libc: Extend __libc_freeres framework (Bug 23329).
The __libc_freeres framework does not extend to non-libc.so objects.
This causes problems in general for valgrind and mtrace detecting
unfreed objects in both libdl.so and libpthread.so. This change is
a pre-requisite to properly moving the malloc hooks out of malloc
since such a move now requires precise accounting of all allocated
data before destructors are run.
This commit adds a proper hook in libc.so.6 for both libdl.so and
for libpthread.so, this ensures that shm-directory.c which uses
freeit () to free memory is called properly. We also remove the
nptl_freeres hook and fall back to using weak-ref-and-check idiom
for a loaded libpthread.so, thus making this process similar for
all DSOs.
Lastly we follow best practice and use explicit free calls for
both libdl.so and libpthread.so instead of the generic hook process
which has undefined order.
Tested on x86_64 with no regressions.
Signed-off-by: DJ Delorie <dj@redhat.com>
Signed-off-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'dlfcn/dlerror.c')
-rw-r--r-- | dlfcn/dlerror.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/dlfcn/dlerror.c b/dlfcn/dlerror.c index 04dce9d..33574fa 100644 --- a/dlfcn/dlerror.c +++ b/dlfcn/dlerror.c @@ -24,6 +24,7 @@ #include <string.h> #include <libc-lock.h> #include <ldsodefs.h> +#include <libc-symbols.h> #if !defined SHARED && IS_IN (libdl) @@ -222,6 +223,19 @@ free_key_mem (void *mem) # ifdef SHARED +/* Free the dlerror-related resources. */ +void +__dlerror_main_freeres (void) +{ + void *mem; + /* Free the global memory if used. */ + check_free (&last_result); + /* Free the TSD memory if used. */ + mem = __libc_getspecific (key); + if (mem != NULL) + free_key_mem (mem); +} + struct dlfcn_hook *_dlfcn_hook __attribute__((nocommon)); libdl_hidden_data_def (_dlfcn_hook) |