blob: 4976d55c1919a032e21595c2c9642378516176c6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/* Copyright (C) 1997-2024 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
<https://www.gnu.org/licenses/>. */
#include <array_length.h>
#include <atomic.h>
#include <stdlib.h>
#include <libc-internal.h>
#include <unwind-link.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
#ifdef USE_NSCD
# 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
#endif
# 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
# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31)
# pragma weak __rpc_freemem
# pragma weak __rpc_thread_destroy
# endif
# 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
# pragma weak __libc_fgetgrent_freemem_ptr
# pragma weak __libc_fgetsgent_freeres_ptr
# pragma weak __libc_getnetgrent_freemem_ptr
# pragma weak __libc_rcmd_freemem_ptr
# pragma weak __libc_rexec_freemem_ptr
# pragma weak __libc_mntent_freemem_ptr
# pragma weak __libc_fgetpwent_freemem_ptr
# pragma weak __libc_getspent_freemem_ptr
# pragma weak __libc_resolv_res_hconf_freemem_ptr
# pragma weak __libc_fgetspent_freemem_ptr
# pragma weak __libc_tzfile_freemem_ptr
# pragma weak __libc_getnameinfo_freemem_ptr
# pragma weak __libc_getutent_freemem_ptr
# pragma weak __libc_getutid_freemem_ptr
# pragma weak __libc_getutline_freemem_ptr
# pragma weak __libc_reg_printf_freemem_ptr
# pragma weak __libc_reg_type_freemem_ptr
# pragma weak __libc_getgrgid_freemem_ptr
# pragma weak __libc_getgrnam_freemem_ptr
# pragma weak __libc_getpwnam_freemem_ptr
# pragma weak __libc_getpwuid_freemem_ptr
# pragma weak __libc_getspnam_freemem_ptr
# pragma weak __libc_getaliasbyname_freemem_ptr
# pragma weak __libc_gethostbyaddr_freemem_ptr
# pragma weak __libc_gethostbyname_freemem_ptr
# pragma weak __libc_gethostbyname2_freemem_ptr
# pragma weak __libc_getnetbyaddr_freemem_ptr
# pragma weak __libc_getnetbyname_freemem_ptr
# pragma weak __libc_getprotobynumber_freemem_ptr
# pragma weak __libc_getprotobyname_freemem_ptr
# pragma weak __libc_getrpcbyname_freemem_ptr
# pragma weak __libc_getrpcbynumber_freemem_ptr
# pragma weak __libc_getservbyname_freemem_ptr
# pragma weak __libc_getservbyport_freemem_ptr
# pragma weak __libc_getgrent_freemem_ptr
# pragma weak __libc_getpwent_freemem_ptr
# pragma weak __libc_getaliasent_freemem_ptr
# pragma weak __libc_gethostent_freemem_ptr
# pragma weak __libc_getnetent_freemem_ptr
# pragma weak __libc_getprotoent_freemem_ptr
# pragma weak __libc_getrpcent_freemem_ptr
# pragma weak __libc_getservent_freemem_ptr
# pragma weak __libc_efgcvt_freemem_ptr
# pragma weak __libc_qefgcvt_freemem_ptr
# pragma weak __libc_qefgcvt_freemem_ptr
# pragma weak __ttyname_freemem_ptr
#endif
#ifdef SHARED
# define call_free_static_weak(__ptr) \
free (__ptr)
#else
# define call_free_static_weak(__ptr) \
if (&__ptr != NULL) \
free (__ptr);
#endif
void
__libc_freeres (void)
{
/* This function might be called from different places. So better
protect for multiple executions since these are fatal. */
static long int already_called;
if (!atomic_compare_and_exchange_bool_acq (&already_called, 1, 0))
{
call_function_static_weak (__nss_module_freeres);
call_function_static_weak (__nss_action_freeres);
call_function_static_weak (__nss_database_freeres);
_IO_cleanup ();
/* We run the resource freeing after IO cleanup. */
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);
#ifdef USE_NSCD
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);
#endif
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);
#ifdef SHARED
__libc_unwind_link_freeres ();
#endif
call_function_static_weak (__libc_dlerror_result_free);
#ifdef SHARED
GLRO (dl_libc_freeres) ();
#endif
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)
|