1 /* Copyright (C) 1997-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <array_length.h>
21 #include <libc-internal.h>
22 #include <unwind-link.h>
24 #include <set-freeres.h>
25 #include <set-freeres-system.h>
28 # pragma weak __nss_module_freeres
29 # pragma weak __nss_action_freeres
30 # pragma weak __nss_database_freeres
31 # pragma weak __dl_libc_freemem
32 # pragma weak __hdestroy
33 # pragma weak __gconv_cache_freemem
34 # pragma weak __gconv_conf_freemem
35 # pragma weak __gconv_db_freemem
36 # pragma weak __gconv_dl_freemem
37 # pragma weak __intl_freemem
38 # pragma weak __libio_freemem
39 # pragma weak __libc_fstab_freemem
41 # pragma weak __nscd_gr_map_freemem
42 # pragma weak __nscd_hst_map_freemem
43 # pragma weak __nscd_pw_map_freemem
44 # pragma weak __nscd_serv_map_freemem
45 # pragma weak __nscd_group_map_freemem
47 # pragma weak __libc_regcomp_freemem
48 # pragma weak __libc_atfork_freemem
49 # pragma weak __res_thread_freeres
50 # pragma weak __libc_resolv_conf_freemem
51 # pragma weak __libc_printf_freemem
52 # pragma weak __libc_fmtmsg_freemem
53 # pragma weak __libc_setenv_freemem
54 # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31)
55 # pragma weak __rpc_freemem
56 # pragma weak __rpc_thread_destroy
58 # pragma weak __libc_getaddrinfo_freemem
59 # pragma weak __libc_tzset_freemem
60 # pragma weak __libc_localealias_freemem
61 # pragma weak __gai_freemem
62 # pragma weak __aio_freemem
63 # pragma weak __libpthread_freeres
64 # pragma weak __libc_dlerror_result_free
65 # pragma weak __check_pf_freemem
66 # pragma weak __libc_fgetgrent_freemem_ptr
67 # pragma weak __libc_fgetsgent_freeres_ptr
68 # pragma weak __libc_getnetgrent_freemem_ptr
69 # pragma weak __libc_rcmd_freemem_ptr
70 # pragma weak __libc_rexec_freemem_ptr
71 # pragma weak __libc_mntent_freemem_ptr
72 # pragma weak __libc_fgetpwent_freemem_ptr
73 # pragma weak __libc_getspent_freemem_ptr
74 # pragma weak __libc_resolv_res_hconf_freemem_ptr
75 # pragma weak __libc_fgetspent_freemem_ptr
76 # pragma weak __libc_tzfile_freemem_ptr
77 # pragma weak __libc_getnameinfo_freemem_ptr
78 # pragma weak __libc_getutent_freemem_ptr
79 # pragma weak __libc_getutid_freemem_ptr
80 # pragma weak __libc_getutline_freemem_ptr
81 # pragma weak __libc_reg_printf_freemem_ptr
82 # pragma weak __libc_reg_type_freemem_ptr
83 # pragma weak __libc_getgrgid_freemem_ptr
84 # pragma weak __libc_getgrnam_freemem_ptr
85 # pragma weak __libc_getpwnam_freemem_ptr
86 # pragma weak __libc_getpwuid_freemem_ptr
87 # pragma weak __libc_getspnam_freemem_ptr
88 # pragma weak __libc_getaliasbyname_freemem_ptr
89 # pragma weak __libc_gethostbyaddr_freemem_ptr
90 # pragma weak __libc_gethostbyname_freemem_ptr
91 # pragma weak __libc_gethostbyname2_freemem_ptr
92 # pragma weak __libc_getnetbyaddr_freemem_ptr
93 # pragma weak __libc_getnetbyname_freemem_ptr
94 # pragma weak __libc_getprotobynumber_freemem_ptr
95 # pragma weak __libc_getprotobyname_freemem_ptr
96 # pragma weak __libc_getrpcbyname_freemem_ptr
97 # pragma weak __libc_getrpcbynumber_freemem_ptr
98 # pragma weak __libc_getservbyname_freemem_ptr
99 # pragma weak __libc_getservbyport_freemem_ptr
100 # pragma weak __libc_getgrent_freemem_ptr
101 # pragma weak __libc_getpwent_freemem_ptr
102 # pragma weak __libc_getaliasent_freemem_ptr
103 # pragma weak __libc_gethostent_freemem_ptr
104 # pragma weak __libc_getnetent_freemem_ptr
105 # pragma weak __libc_getprotoent_freemem_ptr
106 # pragma weak __libc_getrpcent_freemem_ptr
107 # pragma weak __libc_getservent_freemem_ptr
108 # pragma weak __libc_efgcvt_freemem_ptr
109 # pragma weak __libc_qefgcvt_freemem_ptr
110 # pragma weak __libc_qefgcvt_freemem_ptr
111 # pragma weak __ttyname_freemem_ptr
115 # define call_free_static_weak(__ptr) \
118 # define call_free_static_weak(__ptr) \
119 if (&__ptr != NULL) \
124 __libc_freeres (void)
126 /* This function might be called from different places. So better
127 protect for multiple executions since these are fatal. */
128 static long int already_called
;
130 if (!atomic_compare_and_exchange_bool_acq (&already_called
, 1, 0))
132 call_function_static_weak (__nss_module_freeres
);
133 call_function_static_weak (__nss_action_freeres
);
134 call_function_static_weak (__nss_database_freeres
);
138 /* We run the resource freeing after IO cleanup. */
139 call_function_static_weak (__dl_libc_freemem
);
140 call_function_static_weak (__hdestroy
);
141 call_function_static_weak (__gconv_cache_freemem
);
142 call_function_static_weak (__gconv_conf_freemem
);
143 call_function_static_weak (__gconv_db_freemem
);
144 call_function_static_weak (__gconv_dl_freemem
);
145 call_function_static_weak (__intl_freemem
);
146 call_function_static_weak (__libio_freemem
);
147 call_function_static_weak (__libc_fstab_freemem
);
150 call_function_static_weak (__nscd_gr_map_freemem
);
151 call_function_static_weak (__nscd_hst_map_freemem
);
152 call_function_static_weak (__nscd_pw_map_freemem
);
153 call_function_static_weak (__nscd_serv_map_freemem
);
154 call_function_static_weak (__nscd_group_map_freemem
);
157 call_function_static_weak (__libc_regcomp_freemem
);
158 call_function_static_weak (__libc_atfork_freemem
);
159 /* __res_thread_freeres deallocates the per-thread resolv_context);
160 which in turn drop the reference count of the current global object.
161 So it need to be before __libc_resolv_conf_freemem. */
162 call_function_static_weak (__res_thread_freeres
);
163 call_function_static_weak (__libc_resolv_conf_freemem
);
164 call_function_static_weak (__libc_printf_freemem
);
165 call_function_static_weak (__libc_fmtmsg_freemem
);
166 call_function_static_weak (__libc_setenv_freemem
);
167 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31)
168 call_function_static_weak (__rpc_freemem
);
169 call_function_static_weak (__rpc_thread_destroy
);
171 call_function_static_weak (__libc_getaddrinfo_freemem
);
172 call_function_static_weak (__libc_tzset_freemem
);
173 call_function_static_weak (__libc_localealias_freemem
);
176 call_function_static_weak (__gai_freemem
);
178 call_function_static_weak (__aio_freemem
);
181 call_function_static_weak (__libpthread_freeres
);
184 __libc_unwind_link_freeres ();
187 call_function_static_weak (__libc_dlerror_result_free
);
190 GLRO (dl_libc_freeres
) ();
193 call_free_static_weak (__libc_fgetgrent_freemem_ptr
);
194 call_free_static_weak (__libc_fgetsgent_freeres_ptr
);
195 call_free_static_weak (__libc_getnetgrent_freemem_ptr
);
196 call_free_static_weak (__libc_rcmd_freemem_ptr
);
197 call_free_static_weak (__libc_rexec_freemem_ptr
);
198 call_free_static_weak (__libc_mntent_freemem_ptr
);
199 call_free_static_weak (__libc_fgetpwent_freemem_ptr
);
200 call_free_static_weak (__libc_resolv_res_hconf_freemem_ptr
);
201 call_free_static_weak (__libc_fgetspent_freemem_ptr
);
202 call_free_static_weak (__libc_tzfile_freemem_ptr
);
203 call_free_static_weak (__libc_getnameinfo_freemem_ptr
);
204 call_free_static_weak (__libc_getutent_freemem_ptr
);
205 call_free_static_weak (__libc_getutid_freemem_ptr
);
206 call_free_static_weak (__libc_getutline_freemem_ptr
);
207 call_free_static_weak (__libc_reg_printf_freemem_ptr
);
208 call_free_static_weak (__libc_reg_type_freemem_ptr
);
210 call_free_static_weak (__libc_getgrgid_freemem_ptr
);
211 call_free_static_weak (__libc_getgrnam_freemem_ptr
);
212 call_free_static_weak (__libc_getpwnam_freemem_ptr
);
213 call_free_static_weak (__libc_getpwuid_freemem_ptr
);
214 call_free_static_weak (__libc_getspnam_freemem_ptr
);
215 call_free_static_weak (__libc_getaliasbyname_freemem_ptr
);
216 call_free_static_weak (__libc_gethostbyaddr_freemem_ptr
);
217 call_free_static_weak (__libc_gethostbyname_freemem_ptr
);
218 call_free_static_weak (__libc_gethostbyname2_freemem_ptr
);
219 call_free_static_weak (__libc_getnetbyaddr_freemem_ptr
);
220 call_free_static_weak (__libc_getnetbyname_freemem_ptr
);
221 call_free_static_weak (__libc_getprotobynumber_freemem_ptr
);
222 call_free_static_weak (__libc_getprotobyname_freemem_ptr
);
223 call_free_static_weak (__libc_getrpcbyname_freemem_ptr
);
224 call_free_static_weak (__libc_getrpcbynumber_freemem_ptr
);
225 call_free_static_weak (__libc_getservbyname_freemem_ptr
);
226 call_free_static_weak (__libc_getservbyport_freemem_ptr
);
228 call_free_static_weak (__libc_getgrent_freemem_ptr
);
229 call_free_static_weak (__libc_getpwent_freemem_ptr
);
230 call_free_static_weak (__libc_getspent_freemem_ptr
);
231 call_free_static_weak (__libc_getaliasent_freemem_ptr
);
232 call_free_static_weak (__libc_gethostent_freemem_ptr
);
233 call_free_static_weak (__libc_getnetent_freemem_ptr
);
234 call_free_static_weak (__libc_getprotoent_freemem_ptr
);
235 call_free_static_weak (__libc_getrpcent_freemem_ptr
);
236 call_free_static_weak (__libc_getservent_freemem_ptr
);
238 call_free_static_weak (__libc_efgcvt_freemem_ptr
);
239 call_free_static_weak (__libc_qefgcvt_freemem_ptr
);
241 call_freeres_system_funcs
;
244 libc_hidden_def (__libc_freeres
)