@@ -22,7 +22,7 @@ include ../Makeconfig
headers := bits/dlfcn.h dlfcn.h
extra-libs := libdl
libdl-routines := dlopen dlclose dlsym dlvsym dlerror dladdr dladdr1 dlinfo \
- dlmopen dlfcn
+ dlmopen dlfcn dlfreeres
routines := $(patsubst %,s%,$(filter-out dlfcn,$(libdl-routines)))
elide-routines.os := $(routines)
@@ -13,5 +13,6 @@ libdl {
}
GLIBC_PRIVATE {
_dlfcn_hook;
+ __libdl_freeres;
}
}
@@ -215,13 +215,27 @@ static void
free_key_mem (void *mem)
{
check_free ((struct dl_action_result *) mem);
-
free (mem);
__libc_setspecific (key, NULL);
}
# ifdef SHARED
+void
+dlerror_main_freeres (void)
+{
+ void *mem;
+
+ mem = __libc_getspecific (key);
+
+ if (mem)
+ {
+ free (mem);
+ __libc_setspecific (key, NULL);
+ }
+}
+text_set_element (libdl_freeres_hooks, dlerror_main_freeres);
+
struct dlfcn_hook *_dlfcn_hook __attribute__((nocommon));
libdl_hidden_data_def (_dlfcn_hook)
new file mode 100644
@@ -0,0 +1,23 @@
+/* Clean up allocated libdl memory on demand.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <set-hooks.h>
+
+DEFINE_HOOK (libdl_freeres_hooks, (void))
+
+DEFINE_HOOK_RUNNER (libdl_freeres_hooks, __libdl_freeres, (void), ())
new file mode 100644
@@ -0,0 +1 @@
+#include "dlfreeres.c"
@@ -26,6 +26,8 @@ DEFINE_HOOK (__libc_subfreeres, (void));
symbol_set_define (__libc_freeres_ptrs);
+extern __attribute__((weak)) void __libdl_freeres (void);
+
void __libc_freeres_fn_section
__libc_freeres (void)
{
@@ -41,6 +43,10 @@ __libc_freeres (void)
RUN_HOOK (__libc_subfreeres, ());
+ /* This hooks into libdl.so's table of things-to-be-freed. */
+ if (__libdl_freeres)
+ __libdl_freeres ();
+
for (p = symbol_set_first_element (__libc_freeres_ptrs);
!symbol_set_end_p (__libc_freeres_ptrs, p); ++p)
free (*p);