diff options
Diffstat (limited to 'malloc/set-freeres.c')
-rw-r--r-- | malloc/set-freeres.c | 156 |
1 files changed, 133 insertions, 23 deletions
diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c index 4a5cec5d4a..f452ff838b 100644 --- a/malloc/set-freeres.c +++ b/malloc/set-freeres.c @@ -15,32 +15,62 @@ License along with the GNU C Library; if not, see <https://www.gnu.org/licenses/>. */ +#include <array_length.h> #include <atomic.h> #include <stdlib.h> -#include <set-hooks.h> #include <libc-internal.h> #include <unwind-link.h> -#include <dlfcn/dlerror.h> #include <ldsodefs.h> +#include <set-freeres.h> +#include <set-freeres-system.h> + +#ifndef SHARED +# pragma weak __nss_module_freeres +# pragma weak __nss_action_freeres +# pragma weak __nss_database_freeres +# pragma weak __dl_libc_freemem +# pragma weak __hdestroy +# pragma weak __gconv_cache_freemem +# pragma weak __gconv_conf_freemem +# pragma weak __gconv_db_freemem +# pragma weak __gconv_dl_freemem +# pragma weak __intl_freemem +# pragma weak __libio_freemem +# pragma weak __libc_fstab_freemem +# pragma weak __nscd_gr_map_freemem +# pragma weak __nscd_hst_map_freemem +# pragma weak __nscd_pw_map_freemem +# pragma weak __nscd_serv_map_freemem +# pragma weak __nscd_group_map_freemem +# pragma weak __libc_regcomp_freemem +# pragma weak __libc_atfork_freemem +# pragma weak __res_thread_freeres +# pragma weak __libc_resolv_conf_freemem +# pragma weak __libc_printf_freemem +# pragma weak __libc_fmtmsg_freemem +# pragma weak __libc_setenv_freemem +# pragma weak __rpc_freemem +# pragma weak __rpc_thread_destroy +# pragma weak __libc_getaddrinfo_freemem +# pragma weak __libc_tzset_freemem +# pragma weak __libc_localealias_freemem +# pragma weak __gai_freemem +# pragma weak __aio_freemem +# pragma weak __libpthread_freeres +# pragma weak __libc_dlerror_result_free +# pragma weak __check_pf_freemem +#endif -#include "../nss/nsswitch.h" -#include "../libio/libioP.h" - -DEFINE_HOOK (__libc_subfreeres, (void)); - -symbol_set_define (__libc_freeres_ptrs); - -extern void __libpthread_freeres (void) -#if PTHREAD_IN_LIBC && defined SHARED -/* It is possible to call __libpthread_freeres directly in shared - builds with an integrated libpthread. */ - attribute_hidden +#ifdef SHARED +# define call_free_static_weak(__ptr) \ + free (__ptr) #else - __attribute__ ((weak)) +# define call_free_static_weak(__ptr) \ + if (&__ptr != NULL) \ + free (__ptr); #endif - ; -void __libc_freeres_fn_section +void __libc_freeres (void) { /* This function might be called from different places. So better @@ -49,8 +79,6 @@ __libc_freeres (void) if (!atomic_compare_and_exchange_bool_acq (&already_called, 1, 0)) { - void *const *p; - call_function_static_weak (__nss_module_freeres); call_function_static_weak (__nss_action_freeres); call_function_static_weak (__nss_database_freeres); @@ -58,7 +86,43 @@ __libc_freeres (void) _IO_cleanup (); /* We run the resource freeing after IO cleanup. */ - RUN_HOOK (__libc_subfreeres, ()); + call_function_static_weak (__dl_libc_freemem); + call_function_static_weak (__hdestroy); + call_function_static_weak (__gconv_cache_freemem); + call_function_static_weak (__gconv_conf_freemem); + call_function_static_weak (__gconv_db_freemem); + call_function_static_weak (__gconv_dl_freemem); + call_function_static_weak (__intl_freemem); + call_function_static_weak (__libio_freemem); + call_function_static_weak (__libc_fstab_freemem); + call_function_static_weak (__nscd_gr_map_freemem); + call_function_static_weak (__nscd_hst_map_freemem); + call_function_static_weak (__nscd_pw_map_freemem); + call_function_static_weak (__nscd_serv_map_freemem); + call_function_static_weak (__nscd_group_map_freemem); + call_function_static_weak (__libc_regcomp_freemem); + call_function_static_weak (__libc_atfork_freemem); + /* __res_thread_freeres deallocates the per-thread resolv_context); + which in turn drop the reference count of the current global object. + So it need to be before __libc_resolv_conf_freemem. */ + call_function_static_weak (__res_thread_freeres); + call_function_static_weak (__libc_resolv_conf_freemem); + call_function_static_weak (__libc_printf_freemem); + call_function_static_weak (__libc_fmtmsg_freemem); + call_function_static_weak (__libc_setenv_freemem); +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31) + call_function_static_weak (__rpc_freemem); + call_function_static_weak (__rpc_thread_destroy); +#endif + call_function_static_weak (__libc_getaddrinfo_freemem); + call_function_static_weak (__libc_tzset_freemem); + call_function_static_weak (__libc_localealias_freemem); + +#if PTHREAD_IN_LIBC + call_function_static_weak (__gai_freemem); + + call_function_static_weak (__aio_freemem); +#endif call_function_static_weak (__libpthread_freeres); @@ -72,9 +136,55 @@ __libc_freeres (void) GLRO (dl_libc_freeres) (); #endif - for (p = symbol_set_first_element (__libc_freeres_ptrs); - !symbol_set_end_p (__libc_freeres_ptrs, p); ++p) - free (*p); + call_free_static_weak (__libc_fgetgrent_freemem_ptr); + call_free_static_weak (__libc_fgetsgent_freeres_ptr); + call_free_static_weak (__libc_getnetgrent_freemem_ptr); + call_free_static_weak (__libc_rcmd_freemem_ptr); + call_free_static_weak (__libc_rexec_freemem_ptr); + call_free_static_weak (__libc_mntent_freemem_ptr); + call_free_static_weak (__libc_fgetpwent_freemem_ptr); + call_free_static_weak (__libc_resolv_res_hconf_freemem_ptr); + call_free_static_weak (__libc_fgetspent_freemem_ptr); + call_free_static_weak (__libc_tzfile_freemem_ptr); + call_free_static_weak (__libc_getnameinfo_freemem_ptr); + call_free_static_weak (__libc_getutent_freemem_ptr); + call_free_static_weak (__libc_getutid_freemem_ptr); + call_free_static_weak (__libc_getutline_freemem_ptr); + call_free_static_weak (__libc_reg_printf_freemem_ptr); + call_free_static_weak (__libc_reg_type_freemem_ptr); + + call_free_static_weak (__libc_getgrgid_freemem_ptr); + call_free_static_weak (__libc_getgrnam_freemem_ptr); + call_free_static_weak (__libc_getpwnam_freemem_ptr); + call_free_static_weak (__libc_getpwuid_freemem_ptr); + call_free_static_weak (__libc_getspnam_freemem_ptr); + call_free_static_weak (__libc_getaliasbyname_freemem_ptr); + call_free_static_weak (__libc_gethostbyaddr_freemem_ptr); + call_free_static_weak (__libc_gethostbyname_freemem_ptr); + call_free_static_weak (__libc_gethostbyname2_freemem_ptr); + call_free_static_weak (__libc_getnetbyaddr_freemem_ptr); + call_free_static_weak (__libc_getnetbyname_freemem_ptr); + call_free_static_weak (__libc_getprotobynumber_freemem_ptr); + call_free_static_weak (__libc_getprotobyname_freemem_ptr); + call_free_static_weak (__libc_getrpcbyname_freemem_ptr); + call_free_static_weak (__libc_getrpcbynumber_freemem_ptr); + call_free_static_weak (__libc_getservbyname_freemem_ptr); + call_free_static_weak (__libc_getservbyport_freemem_ptr); + + call_free_static_weak (__libc_getgrent_freemem_ptr); + call_free_static_weak (__libc_getpwent_freemem_ptr); + call_free_static_weak (__libc_getspent_freemem_ptr); + call_free_static_weak (__libc_getaliasent_freemem_ptr); + call_free_static_weak (__libc_gethostent_freemem_ptr); + call_free_static_weak (__libc_getnetent_freemem_ptr); + call_free_static_weak (__libc_getprotoent_freemem_ptr); + call_free_static_weak (__libc_getrpcent_freemem_ptr); + call_free_static_weak (__libc_getservent_freemem_ptr); + + call_free_static_weak (__libc_efgcvt_freemem_ptr); + call_free_static_weak (__libc_qefgcvt_freemem_ptr); + + call_freeres_system_funcs; } } libc_hidden_def (__libc_freeres) |