about summary refs log tree commit diff
path: root/malloc/thread-freeres.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-04-21 19:49:51 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-04-21 19:49:51 +0200
commitfada9018199c21c469ff0e731ef75c6020074ac9 (patch)
tree92a5914178f7acac985fd4ce15d4e7ee99522e9d /malloc/thread-freeres.c
parentb2964eb1d9a6b8ab1250e8a881cf406182da5875 (diff)
downloadglibc-fada9018199c21c469ff0e731ef75c6020074ac9.tar.gz
glibc-fada9018199c21c469ff0e731ef75c6020074ac9.tar.xz
glibc-fada9018199c21c469ff0e731ef75c6020074ac9.zip
dlfcn: dlerror needs to call free from the base namespace [BZ #24773]
Calling free directly may end up freeing a pointer allocated by the
dynamic loader using malloc from libc.so in the base namespace using
the allocator from libc.so in a secondary namespace, which results in
crashes.

This commit redirects the free call through GLRO and the dynamic
linker, to reach the correct namespace.  It also cleans up the dlerror
handling along the way, so that pthread_setspecific is no longer
needed (which avoids triggering bug 24774).
Diffstat (limited to 'malloc/thread-freeres.c')
-rw-r--r--malloc/thread-freeres.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/malloc/thread-freeres.c b/malloc/thread-freeres.c
index da76a3dca7..77a204f9fa 100644
--- a/malloc/thread-freeres.c
+++ b/malloc/thread-freeres.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <dlfcn/dlerror.h>
 #include <libc-internal.h>
 #include <malloc-internal.h>
 #include <resolv/resolv-internal.h>
@@ -36,6 +37,7 @@ __libc_thread_freeres (void)
 #endif
   call_function_static_weak (__res_thread_freeres);
   __glibc_tls_internal_free ();
+  call_function_static_weak (__libc_dlerror_result_free);
 
   /* This should come last because it shuts down malloc for this
      thread and the other shutdown functions might well call free.  */