New macros.
* elf/dl-close.c (free_mem): Use libc_freeres_fn macro, remove
text_set_element.
* elf/dl-libc.c (free_mem): Likewise.
* iconv/gconv_conf.c (free_mem): Likewise.
* iconv/gconv_db.c (free_mem): Likewise.
* iconv/gconv_dl.c (free_mem): Likewise.
* iconv/gconv_cache.c (free_mem): Likewise.
* intl/finddomain.c (free_mem): Likewise.
* intl/dcigettext.c (free_mem): Likewise.
* locale/setlocale.c (free_mem): Likewise.
* misc/fstab.c (fstab_free): Likewise.
* nss/nsswitch.c (free_mem): Likewise.
* posix/regcomp.c (free_mem): Likewise.
* resolv/gai_misc.c (free_res): Likewise.
* stdlib/fmtmsg.c (free_mem): Likewise.
* sunrpc/clnt_perr.c (free_mem): Likewise.
* sysdeps/generic/setenv.c (free_mem): Likewise.
* sysdeps/unix/sysv/linux/shm_open.c (freeit): Likewise.
* sysdeps/pthread/aio_misc.c (free_res): Likewise.
* time/tzset.c (free_mem): Likewise.
* malloc/mtrace.c (release_libc_mem): Add __libc_freeres_fn_section.
* locale/loadarchive.c (_nl_archive_subfreeres): Likewise.
* malloc/set-freeres.c (__libc_freeres): Likewise.
* login/getutent.c: Include stdlib.h instead of stddef.h.
(buffer): Change into pointer to utmp, add libc_freeres_ptr.
(__getutent): Allocate buffer the first time it is run.
* login/getutid.c: Include stdlib.h instead of stddef.h.
(buffer): Change into pointer to utmp, add libc_freeres_ptr.
(__getutid): Allocate buffer the first time it is run.
* login/getutline.c: Include stdlib.h instead of stddef.h.
(buffer): Change into pointer to utmp, add libc_freeres_ptr.
(__getutline): Allocate buffer the first time it is run.
* malloc/mtrace.c (malloc_trace_buffer): Change into char *.
(mtrace): Allocate malloc_trace_buffer.
* resolv/nsap_addr.c (inet_nsap_ntoa): Decrease size of tmpbuf.
* resolv/ns_print.c (ns_sprintrrf): Decrease size of t.
* string/strerror.c: Include libintl.h and errno.h.
(buf): New variable.
(strerror): Only allocate buffer if actually needed (unknown error).
* time/tzfile.c (transitions): Add libc_freeres_ptr.
(freeres): Remove.
2002-10-25 Jakub Jelinek <jakub@redhat.com>
* include/libc-symbols.h (libc_freeres_ptr): New macro.
* malloc/set-freeres.c (__libc_freeres_ptrs): Define using
symbol_set_define.
(__libc_freeres): Free all pointers in that section.
* Makerules (build-shlib): Add $(LDSEDCMD-$(@F:lib%.so=%).so) to sed
commands when creating .lds script.
(LDSEDCMD-c.so): New variable.
* inet/rcmd.c (ahostbuf): Change into char *. Add libc_freeres_ptr.
(rcmd_af): Use strdup to allocate ahostbuf.
* inet/rexec.c (ahostbuf): Change into char *. Add libc_freeres_ptr.
(rexec_af): Use strdup to allocate ahostbuf.
* stdio-common/reg-printf.c (printf_funcs): Remove.
(__printf_arginfo_table): Change into printf_arginfo_function **.
Add libc_freeres_ptr.
(__register_printf_function): Allocate __printf_arginfo_table
and __printf_function_table the first time it is called.
* stdio-common/printf-parse.h (__printf_arginfo_table): Change into
printf_arginfo_function **.
(parse_one_spec): Add __builtin_expect.
* grp/fgetgrent.c (buffer): Add libc_freeres_ptr.
(free_mem): Remove.
* inet/getnetgrent.c (buffer): Add libc_freeres_ptr.
(free_mem): Remove.
* intl/localealias.c (libc_freeres_ptr): Define if !_LIBC.
(string_space, map): Add libc_freeres_ptr.
(free_mem): Remove.
* misc/efgcvt.c (FCVT_BUFPTR): Add libc_freeres_ptr.
(free_mem): Remove.
* misc/mntent.c (getmntent_buffer): Add libc_freeres_ptr.
(free_mem): Remove.
* crypt/md5-crypt.c (libc_freeres_ptr): Define if !_LIBC.
(buffer): Add libc_freeres_ptr.
(free_mem): Remove for _LIBC.
* nss/getXXbyYY.c (buffer): Add libc_freeres_ptr.
(free_mem): Remove.
* nss/getXXent.c (buffer): Add libc_freeres_ptr.
(free_mem): Remove.
* pwd/fgetpwent.c (buffer): Add libc_freeres_ptr.
(free_mem): Remove.
* resolv/res_hconf.c (ifaddrs): Add libc_freeres_ptr.
(free_mem): Remove.
* shadow/fgetspent.c (buffer): Add libc_freeres_ptr.
(free_mem): Remove.
* sysdeps/posix/ttyname.c (getttyname_name): Add libc_freeres_ptr.
(free_mem): Remove.
* sysdeps/unix/sysv/linux/getsysstats.c (mount_proc): Add
libc_freeres_ptr.
(free_mem): Remove.
* sysdeps/unix/sysv/linux/ttyname.c (getttyname_name, ttyname_buf): Add
libc_freeres_ptr.
(free_mem): Remove.
2002-10-30 Jakub Jelinek <jakub@redhat.com>
* malloc/obstack.c [_LIBC] (obstack_free): Change into strong_alias
instead of duplicating the whole function in libc.
+2002-10-30 Jakub Jelinek <jakub@redhat.com>
+
+ * include/libc-symbols.h (__libc_freeres_fn_section, libc_freeres_fn):
+ New macros.
+ * elf/dl-close.c (free_mem): Use libc_freeres_fn macro, remove
+ text_set_element.
+ * elf/dl-libc.c (free_mem): Likewise.
+ * iconv/gconv_conf.c (free_mem): Likewise.
+ * iconv/gconv_db.c (free_mem): Likewise.
+ * iconv/gconv_dl.c (free_mem): Likewise.
+ * iconv/gconv_cache.c (free_mem): Likewise.
+ * intl/finddomain.c (free_mem): Likewise.
+ * intl/dcigettext.c (free_mem): Likewise.
+ * locale/setlocale.c (free_mem): Likewise.
+ * misc/fstab.c (fstab_free): Likewise.
+ * nss/nsswitch.c (free_mem): Likewise.
+ * posix/regcomp.c (free_mem): Likewise.
+ * resolv/gai_misc.c (free_res): Likewise.
+ * stdlib/fmtmsg.c (free_mem): Likewise.
+ * sunrpc/clnt_perr.c (free_mem): Likewise.
+ * sysdeps/generic/setenv.c (free_mem): Likewise.
+ * sysdeps/unix/sysv/linux/shm_open.c (freeit): Likewise.
+ * sysdeps/pthread/aio_misc.c (free_res): Likewise.
+ * time/tzset.c (free_mem): Likewise.
+ * malloc/mtrace.c (release_libc_mem): Add __libc_freeres_fn_section.
+ * locale/loadarchive.c (_nl_archive_subfreeres): Likewise.
+ * malloc/set-freeres.c (__libc_freeres): Likewise.
+
+ * login/getutent.c: Include stdlib.h instead of stddef.h.
+ (buffer): Change into pointer to utmp, add libc_freeres_ptr.
+ (__getutent): Allocate buffer the first time it is run.
+ * login/getutid.c: Include stdlib.h instead of stddef.h.
+ (buffer): Change into pointer to utmp, add libc_freeres_ptr.
+ (__getutid): Allocate buffer the first time it is run.
+ * login/getutline.c: Include stdlib.h instead of stddef.h.
+ (buffer): Change into pointer to utmp, add libc_freeres_ptr.
+ (__getutline): Allocate buffer the first time it is run.
+ * malloc/mtrace.c (malloc_trace_buffer): Change into char *.
+ (mtrace): Allocate malloc_trace_buffer.
+ * resolv/nsap_addr.c (inet_nsap_ntoa): Decrease size of tmpbuf.
+ * resolv/ns_print.c (ns_sprintrrf): Decrease size of t.
+ * string/strerror.c: Include libintl.h and errno.h.
+ (buf): New variable.
+ (strerror): Only allocate buffer if actually needed (unknown error).
+ * time/tzfile.c (transitions): Add libc_freeres_ptr.
+ (freeres): Remove.
+
+2002-10-25 Jakub Jelinek <jakub@redhat.com>
+
+ * include/libc-symbols.h (libc_freeres_ptr): New macro.
+ * malloc/set-freeres.c (__libc_freeres_ptrs): Define using
+ symbol_set_define.
+ (__libc_freeres): Free all pointers in that section.
+ * Makerules (build-shlib): Add $(LDSEDCMD-$(@F:lib%.so=%).so) to sed
+ commands when creating .lds script.
+ (LDSEDCMD-c.so): New variable.
+ * inet/rcmd.c (ahostbuf): Change into char *. Add libc_freeres_ptr.
+ (rcmd_af): Use strdup to allocate ahostbuf.
+ * inet/rexec.c (ahostbuf): Change into char *. Add libc_freeres_ptr.
+ (rexec_af): Use strdup to allocate ahostbuf.
+ * stdio-common/reg-printf.c (printf_funcs): Remove.
+ (__printf_arginfo_table): Change into printf_arginfo_function **.
+ Add libc_freeres_ptr.
+ (__register_printf_function): Allocate __printf_arginfo_table
+ and __printf_function_table the first time it is called.
+ * stdio-common/printf-parse.h (__printf_arginfo_table): Change into
+ printf_arginfo_function **.
+ (parse_one_spec): Add __builtin_expect.
+ * grp/fgetgrent.c (buffer): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * inet/getnetgrent.c (buffer): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * intl/localealias.c (libc_freeres_ptr): Define if !_LIBC.
+ (string_space, map): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * misc/efgcvt.c (FCVT_BUFPTR): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * misc/mntent.c (getmntent_buffer): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * crypt/md5-crypt.c (libc_freeres_ptr): Define if !_LIBC.
+ (buffer): Add libc_freeres_ptr.
+ (free_mem): Remove for _LIBC.
+ * nss/getXXbyYY.c (buffer): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * nss/getXXent.c (buffer): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * pwd/fgetpwent.c (buffer): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * resolv/res_hconf.c (ifaddrs): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * shadow/fgetspent.c (buffer): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * sysdeps/posix/ttyname.c (getttyname_name): Add libc_freeres_ptr.
+ (free_mem): Remove.
+ * sysdeps/unix/sysv/linux/getsysstats.c (mount_proc): Add
+ libc_freeres_ptr.
+ (free_mem): Remove.
+ * sysdeps/unix/sysv/linux/ttyname.c (getttyname_name, ttyname_buf): Add
+ libc_freeres_ptr.
+ (free_mem): Remove.
+
+2002-10-30 Jakub Jelinek <jakub@redhat.com>
+
+ * malloc/obstack.c [_LIBC] (obstack_free): Change into strong_alias
+ instead of duplicating the whole function in libc.
+
2002-10-31 Roland McGrath <roland@redhat.com>
* sysdeps/i386/bits/byteswap.h [__GNUC__ < 2] (__bswap_32):
$(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
sed -e '/^=========/,/^=========/!d;/^=========/d' \
-e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
- > $@.lds
+ $(LDSEDCMD-$(@F:lib%.so=%).so) > $@.lds
rm -f $@.new
$(build-shlib-helper) -o $@ -T $@.lds \
$(csu-objpfx)abi-note.o $(build-shlib-objlist)
$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
$(LINK.o) -nostdlib -nostartfiles -r -o $@ \
$(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
+LDSEDCMD-c.so = -e 's/^.*\*(\.dynbss).*$$/& __start___libc_freeres_ptrs = .; *(__libc_freeres_ptrs) __stop___libc_freeres_ptrs = .;/'
# Use our own special initializer and finalizer files for libc.so.
$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
$(common-objpfx)libc_pic.os \
/* One way encryption based on MD5 sum.
- Copyright (C) 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
return buffer;
}
-
-static char *buffer;
+#ifndef _LIBC
+# define libc_freeres_ptr(decl) decl
+#endif
+libc_freeres_ptr (static char *buffer);
char *
__md5_crypt (const char *key, const char *salt)
return __md5_crypt_r (key, salt, buffer, buflen);
}
-
+#ifndef _LIBC
static void
__attribute__ ((__destructor__))
free_mem (void)
{
free (buffer);
}
+#endif
_r_debug.r_state = RT_DELETE;
_dl_debug_state ();
+#ifdef USE_TLS
+ size_t tls_free_start, tls_free_end;
+ tls_free_start = tls_free_end = GL(dl_tls_static_used);
+#endif
+
/* Check each element of the search list to see if all references to
it are gone. */
for (i = 0; list[i] != NULL; ++i)
imap->l_init_called))
/* All dynamically loaded modules with TLS are unloaded. */
GL(dl_tls_max_dtv_idx) = GL(dl_tls_static_nelem);
+
+ if (imap->l_tls_offset != 0)
+ {
+ /* Collect a contiguous chunk built from the objects in
+ this search list, going in either direction. When the
+ whole chunk is at the end of the used area then we can
+ reclaim it. */
+ if (imap->l_tls_offset == tls_free_end)
+ /* Extend the contiguous chunk being reclaimed. */
+ tls_free_end += imap->l_tls_blocksize;
+ else if (imap->l_tls_offset + imap->l_tls_blocksize
+ == tls_free_start)
+ /* Extend the chunk backwards. */
+ tls_free_start = imap->l_tls_offset;
+ else
+ {
+ /* This isn't contiguous with the last chunk freed.
+ One of them will be leaked. */
+ if (tls_free_end == GL(dl_tls_static_used))
+ GL(dl_tls_static_used) = tls_free_start;
+ tls_free_start = imap->l_tls_offset;
+ tls_free_end = tls_free_start + imap->l_tls_blocksize;
+ }
+ }
}
#endif
}
#ifdef USE_TLS
- /* If we removed any object which uses TLS bumnp the generation
- counter. */
+ /* If we removed any object which uses TLS bump the generation counter. */
if (any_tls)
- if (__builtin_expect (++GL(dl_tls_generation) == 0, 0))
- __libc_fatal (_("TLS generation counter wrapped! Please send report with the 'glibcbug' script."));
+ {
+ if (__builtin_expect (++GL(dl_tls_generation) == 0, 0))
+ __libc_fatal (_("TLS generation counter wrapped! Please send report with the 'glibcbug' script."));
+
+ if (tls_free_end == GL(dl_tls_static_used))
+ GL(dl_tls_static_used) = tls_free_start;
+ }
#endif
/* Notify the debugger those objects are finalized and gone. */
#endif
-static void
-free_mem (void)
+libc_freeres_fn (free_mem)
{
if (__builtin_expect (GL(dl_global_scope_alloc), 0) != 0
&& GL(dl_main_searchlist)->r_nlist == GL(dl_initial_searchlist).r_nlist)
GL(dl_tls_dtv_slotinfo_list)->next = NULL;
#endif
}
-text_set_element (__libc_subfreeres, free_mem);
}
-static void
-free_mem (void)
+libc_freeres_fn (free_mem)
{
struct link_map *l;
struct r_search_path_elem *d;
}
}
}
-text_set_element (__libc_subfreeres, free_mem);
-/* Copyright (C) 1991, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1996,1997,1999,2000,2002 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
/* We need to protect the dynamic buffer handling. */
__libc_lock_define_initialized (static, lock);
-static char *buffer;
+libc_freeres_ptr (static char *buffer);
/* Read one entry from the given stream. */
struct group *
return result;
}
-
-
-/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
-{
- free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
if (cache_malloced)
free (gconv_cache);
__munmap (gconv_cache, cache_size);
#endif
}
-
-text_set_element (__libc_subfreeres, free_mem);
/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
if (__gconv_path_elem != NULL && __gconv_path_elem != &empty_path_elem)
free ((void *) __gconv_path_elem);
}
-
-text_set_element (__libc_subfreeres, free_mem);
/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
if (__gconv_alias_db != NULL)
__tdestroy (__gconv_alias_db, free);
if (known_derivations != NULL)
__tdestroy (known_derivations, free_derivation);
}
-
-text_set_element (__libc_subfreeres, free_mem);
free (obj);
}
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
__tdestroy (loaded, do_release_all);
}
-text_set_element (__libc_subfreeres, free_mem);
#ifdef DEBUG
/* Tacking on "\n\t#" to the section name makes gcc put it's bogus
section attributes on what looks like a comment to the assembler. */
# ifdef HAVE_SECTION_QUOTES
-# define link_warning(symbol, msg) \
- __make_section_unallocated (".gnu.warning." #symbol) \
- static const char __evoke_link_warning_##symbol[] \
- __attribute__ ((unused, section (".gnu.warning." #symbol "\"\n\t#\""))) \
- = msg;
+# define __sec_comment "\"\n\t#\""
# else
-# define link_warning(symbol, msg) \
+# define __sec_comment "\n\t#"
+# endif
+# define link_warning(symbol, msg) \
__make_section_unallocated (".gnu.warning." #symbol) \
static const char __evoke_link_warning_##symbol[] \
- __attribute__ ((unused, section (".gnu.warning." #symbol "\n\t#"))) = msg;
-# endif
+ __attribute__ ((unused, section (".gnu.warning." #symbol __sec_comment))) \
+ = msg;
+# define libc_freeres_ptr(decl) \
+ __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", @nobits") \
+ decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
+# define __libc_freeres_fn_section \
+ __attribute__ ((section ("__libc_freeres_fn")))
# else /* Not ELF: a.out */
# ifdef HAVE_XCOFF
/* XCOFF does not support .stabs.
asm (".stabs \"" msg "\",30,0,0,0\n\t" \
".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
# endif /* XCOFF */
+# define libc_freeres_ptr(decl) decl
+# define __libc_freeres_fn_section
# endif
#else
/* We will never be heard; they will all die horribly. */
# define link_warning(symbol, msg)
+# define libc_freeres_ptr(decl) decl
+# define __libc_freeres_fn_section
#endif
+#define libc_freeres_fn(name) \
+ static void name (void) __attribute_used__ __libc_freeres_fn_section; \
+ text_set_element (__libc_subfreeres, name); \
+ static void name (void)
/* A canned warning for sysdeps/stub functions. */
#define stub_warning(name) \
-/* Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 2000, 2002 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
#include <stdlib.h>
#include <bits/libc-lock.h>
-/* Statis buffer for return value. We allocate it when needed. */
-static char *buffer;
+/* Static buffer for return value. We allocate it when needed. */
+libc_freeres_ptr (static char *buffer);
/* All three strings should fit in a block of 1kB size. */
#define BUFSIZE 1024
return __getnetgrent_r (hostp, userp, domainp, buffer, BUFSIZE);
}
-
-
-/* Make sure the memory is freed if the programs ends while in
- memory-debugging mode and something actually was allocated. */
-static void
-__attribute__ ((unused))
-free_mem (void)
-{
- free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
libc_hidden_proto (iruserok_af)
-static char ahostbuf[NI_MAXHOST];
+libc_freeres_ptr(static char *ahostbuf);
int
rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
pfd[1].events = POLLIN;
if (res->ai_canonname){
- strncpy(ahostbuf, res->ai_canonname, sizeof(ahostbuf));
- ahostbuf[sizeof(ahostbuf)-1] = '\0';
+ free (ahostbuf);
+ ahostbuf = strdup (res->ai_canonname);
+ if (ahostbuf == NULL) {
+#ifdef USE_IN_LIBIO
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf(stderr, L"%s",
+ _("rcmd: Cannot allocate memory\n"));
+ else
+#endif
+ fputs(_("rcmd: Cannot allocate memory\n"),
+ stderr);
+ return (-1);
+ }
*ahost = ahostbuf;
- }
- else
+ } else
*ahost = NULL;
ai = res;
refused = 0;
#include <unistd.h>
int rexecoptions;
-static char ahostbuf[NI_MAXHOST];
+libc_freeres_ptr (static char *ahostbuf);
int
rexec_af(ahost, rport, name, pass, cmd, fd2p, af)
}
if (res0->ai_canonname){
- strncpy(ahostbuf, res0->ai_canonname, sizeof(ahostbuf));
- ahostbuf[sizeof(ahostbuf)-1] = '\0';
+ free (ahostbuf);
+ ahostbuf = strdup (res0->ai_canonname);
+ if (ahostbuf == NULL) {
+ perror ("rexec: strdup");
+ return (-1);
+ }
*ahost = ahostbuf;
- }
- else{
+ } else
*ahost = NULL;
- }
ruserpass(res0->ai_canonname, &name, &pass);
retry:
s = __socket(res0->ai_family, res0->ai_socktype, 0);
#ifdef _LIBC
/* If we want to free all resources we have to do some work at
program's end. */
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
void *old;
free (old);
}
}
-
-text_set_element (__libc_subfreeres, free_mem);
#endif
#ifdef _LIBC
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
struct loaded_l10nfile *runp = _nl_loaded_domains;
free (here);
}
}
-
-text_set_element (__libc_subfreeres, free_mem);
#endif
};
-static char *string_space;
+#ifndef _LIBC
+# define libc_freeres_ptr(decl) decl
+#endif
+
+libc_freeres_ptr (static char *string_space);
static size_t string_space_act;
static size_t string_space_max;
-static struct alias_map *map;
+libc_freeres_ptr (static struct alias_map *map);
static size_t nmap;
static size_t maxmap;
}
-#ifdef _LIBC
-static void __attribute__ ((unused))
-free_mem (void)
-{
- if (string_space != NULL)
- free (string_space);
- if (map != NULL)
- free (map);
-}
-text_set_element (__libc_subfreeres, free_mem);
-#endif
-
-
static int
alias_compare (map1, map2)
const struct alias_map *map1;
return lia->data[category];
}
-void
+void __libc_freeres_fn_section
_nl_archive_subfreeres (void)
{
struct locale_in_archive *lia;
}
}
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
#ifdef NL_CURRENT_INDIRECT
/* We don't use the loop because we want to have individual weak
not called _nl_unload_locale on them above. */
_nl_archive_subfreeres ();
}
-text_set_element (__libc_subfreeres, free_mem);
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <stddef.h> /* For NULL. */
+#include <stdlib.h>
#include <utmp.h>
/* Local buffer to store the result. */
-static struct utmp buffer;
+libc_freeres_ptr (static struct utmp *buffer);
struct utmp *
{
struct utmp *result;
- if (__getutent_r (&buffer, &result) < 0)
+ if (buffer == NULL)
+ {
+ buffer = (struct utmp *) malloc (sizeof (struct utmp));
+ if (buffer == NULL)
+ return NULL;
+ }
+
+ if (__getutent_r (buffer, &result) < 0)
return NULL;
return result;
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <stddef.h> /* For NULL. */
+#include <stdlib.h>
#include <utmp.h>
/* Local buffer to store the result. */
-static struct utmp buffer;
-
+libc_freeres_ptr (static struct utmp *buffer);
struct utmp *
__getutid (const struct utmp *id)
{
struct utmp *result;
- if (__getutid_r (id, &buffer, &result) < 0)
+ if (buffer == NULL)
+ {
+ buffer = (struct utmp *) malloc (sizeof (struct utmp));
+ if (buffer == NULL)
+ return NULL;
+ }
+ if (__getutid_r (id, buffer, &result) < 0)
return NULL;
return result;
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <stddef.h> /* For NULL. */
+#include <stdlib.h>
#include <utmp.h>
/* Local buffer to store the result. */
-static struct utmp buffer;
+libc_freeres_ptr (static struct utmp *buffer);
struct utmp *
{
struct utmp *result;
- if (__getutline_r (line, &buffer, &result) < 0)
+ if (buffer == NULL)
+ {
+ buffer = (struct utmp *) malloc (sizeof (struct utmp));
+ if (buffer == NULL)
+ return NULL;
+ }
+ if (__getutline_r (line, buffer, &result) < 0)
return NULL;
return result;
static FILE *mallstream;
static const char mallenv[]= "MALLOC_TRACE";
-static char malloc_trace_buffer[TRACE_BUFFER_SIZE];
+static char *malloc_trace_buffer;
__libc_lock_define_initialized (static, lock);
/* This function gets called to make sure all memory the library
allocates get freed and so does not irritate the user when studying
the mtrace output. */
-static void
+static void __libc_freeres_fn_section
release_libc_mem (void)
{
/* Only call the free function if we still are running in mtrace mode. */
#endif
if (mallfile != NULL || mallwatch != NULL)
{
+ char *mtb = malloc (TRACE_BUFFER_SIZE);
+ if (mtb == NULL)
+ return;
+
mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "w");
if (mallstream != NULL)
{
__fcntl (fileno (mallstream), F_SETFD, flags);
}
/* Be sure it doesn't malloc its buffer! */
+ malloc_trace_buffer = mtb;
setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE);
fprintf (mallstream, "= Start\n");
tr_old_free_hook = __free_hook;
}
#endif
}
+ else
+ free (mtb);
}
}
/* This function is used from ANSI code. */
+#ifdef _LIBC
+strong_alias (_obstack_free, obstack_free)
+#else
+
void
obstack_free (h, obj)
struct obstack *h;
/* obj is not in any of the chunks! */
abort ();
}
+#endif
\f
int
_obstack_memory_used (h)
DEFINE_HOOK (__libc_subfreeres, (void));
-void
+symbol_set_define (__libc_freeres_ptrs);
+
+void __libc_freeres_fn_section
__libc_freeres (void)
{
/* This function might be called from different places. So better
if (compare_and_swap (&already_called, 0, 1))
{
+ void * const *p;
+
#ifdef USE_IN_LIBIO
_IO_cleanup ();
#endif
RUN_HOOK (__libc_subfreeres, ());
+
+ for (p = symbol_set_first_element (__libc_freeres_ptrs);
+ ! symbol_set_end_p (__libc_freeres_ptrs, p); ++p)
+ free (*p);
}
}
libc_hidden_def (__libc_freeres)
/* Compatibility functions for floating point formatting.
- Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1999, 2002 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
static char FCVT_BUFFER[MAXDIG];
static char ECVT_BUFFER[MAXDIG];
-static char *FCVT_BUFPTR;
+libc_freeres_ptr (static char *FCVT_BUFPTR);
char *
APPEND (FUNC_PREFIX, fcvt) (value, ndigit, decpt, sign)
sprintf (buf, "%.*" FLOAT_FMT_FLAG "g", MIN (ndigit, NDIGIT_MAX), value);
return buf;
}
-
-/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
-{
- if (FCVT_BUFPTR != NULL)
- free (FCVT_BUFPTR);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
/* Make sure the memory is freed if the programs ends while in
memory-debugging mode and something actually was allocated. */
-static void
-__attribute__ ((unused))
-fstab_free (void)
+libc_freeres_fn (fstab_free)
{
char *buffer;
if (buffer != NULL)
free ((void *) buffer);
}
-
-text_set_element (__libc_subfreeres, fstab_free);
/* Utilities for reading/writing fstab, mtab, etc.
- Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 2000, 2002 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
/* We don't want to allocate the static buffer all the time since it
is not always used (in fact, rather infrequently). Accept the
extra cost of a `malloc'. */
-static char *getmntent_buffer;
+libc_freeres_ptr (static char *getmntent_buffer);
/* This is the size of the buffer. This is really big. */
#define BUFFER_SIZE 4096
return __getmntent_r (stream, &m, getmntent_buffer, BUFFER_SIZE);
}
-
-
-/* Make sure the memory is freed if the programs ends while in
- memory-debugging mode and something actually was allocated. */
-static void
-__attribute__ ((unused))
-free_mem (void)
-{
- free (getmntent_buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
__libc_lock_define_initialized (static, lock);
/* This points to the static buffer used. */
-static char *buffer;
+libc_freeres_ptr (static char *buffer);
LOOKUP_TYPE *
return result;
}
-
-
-/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
-{
- free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
__libc_lock_define_initialized (static, lock);
/* This points to the static buffer used. */
-static char *buffer;
+libc_freeres_ptr (static char *buffer);
LOOKUP_TYPE *
__set_errno (save);
return result;
}
-
-
-/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
-{
- free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
name_database *top = service_table;
name_database_entry *entry;
free (top);
}
-
-text_set_element (__libc_subfreeres, free_mem);
}
#ifdef _LIBC
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
__regfree (&re_comp_buf);
}
-text_set_element (__libc_subfreeres, free_mem);
#endif
#endif /* _REGEX_RE_COMP */
-/* Copyright (C) 1991, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1996,1997,1999,2000,2002 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
/* We need to protect the dynamic buffer handling. */
__libc_lock_define_initialized (static, lock);
-static char *buffer;
+libc_freeres_ptr (static char *buffer);
/* Read one entry from the given stream. */
struct passwd *
return result;
}
-
-
-/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
-{
- free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
/* Free allocated resources. */
-static void
-__attribute__ ((unused))
-free_res (void)
+libc_freeres_fn (free_res)
{
size_t row;
free (pool);
}
-text_set_element (__libc_subfreeres, free_res);
break;
case ns_t_nsap: {
- char t[255*3];
+ /* 2*255 for hex digits, 128 for '.' and '\0', 2 for
+ 0x if inet_nsap_ntoa starts using it. */
+ char t[255*2 + 128 + 2];
(void) inet_nsap_ntoa(rdlen, rdata, t);
T(addstr(t, strlen(t), &buf, &buflen));
inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) {
int nib;
int i;
- static char tmpbuf[255*3];
+ static char tmpbuf[255*2 + 128];
char *start;
if (ascii)
/* List of known interfaces. */
+libc_freeres_ptr (
static struct netaddr
{
int addrtype;
u_int32_t mask;
} ipv4;
} u;
-} *ifaddrs;
+} *ifaddrs);
/* We need to protect the dynamic buffer handling. */
__libc_lock_define_initialized (static, lock);
for (i = 0; hp->h_aliases[i]; ++i)
_res_hconf_trim_domain (hp->h_aliases[i]);
}
-
-
-/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
-{
- free (ifaddrs);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
-/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1999, 2000, 2002 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
/* We need to protect the dynamic buffer handling. */
__libc_lock_define_initialized (static, lock);
-static char *buffer;
+libc_freeres_ptr (static char *buffer);
/* Read one shadow entry from the given stream. */
struct spwd *
return result;
}
-
-
-/* Free all resources if necessary. */
-static void __attribute__ ((unused))
-free_mem (void)
-{
- free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
/* These are defined in reg-printf.c. */
-extern printf_arginfo_function *__printf_arginfo_table[] attribute_hidden;
+extern printf_arginfo_function **__printf_arginfo_table attribute_hidden;
extern printf_function **__printf_function_table attribute_hidden;
/* Get the format specification. */
spec->info.spec = (wchar_t) *format++;
- if (__printf_function_table != NULL
+ if (__builtin_expect (__printf_function_table != NULL, 0)
&& spec->info.spec <= UCHAR_MAX
&& __printf_arginfo_table[spec->info.spec] != NULL)
/* We don't try to get the types for all arguments if the format
#include <printf.h>
/* Array of functions indexed by format character. */
-static printf_function *printf_funcs[UCHAR_MAX + 1];
-printf_arginfo_function *__printf_arginfo_table[UCHAR_MAX + 1]
- attribute_hidden;
-
+libc_freeres_ptr (printf_arginfo_function **__printf_arginfo_table)
+ attribute_hidden;
printf_function **__printf_function_table attribute_hidden;
int __register_printf_function __P ((int, printf_function,
return -1;
}
- __printf_function_table = printf_funcs;
+ if (__printf_function_table == NULL)
+ {
+ __printf_arginfo_table = (printf_arginfo_function **)
+ malloc ((UCHAR_MAX + 1) * sizeof (void *) * 2);
+ if (__printf_arginfo_table == NULL)
+ return -1;
+ __printf_function_table = (printf_function **)
+ (__printf_arginfo_table + UCHAR_MAX + 1);
+ }
+
+ __printf_function_table[spec] = converter;
__printf_arginfo_table[spec] = arginfo;
- printf_funcs[spec] = converter;
return 0;
}
}
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
struct severity_info *runp = severity_list;
else
runp = runp->next;
}
-text_set_element (__libc_subfreeres, free_mem);
-/* Copyright (C) 1991, 93, 94, 95, 96, 98 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 93, 94, 95, 96, 98, 2002 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
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <libintl.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
/* Return a string describing the errno code in ERRNUM.
The storage is good only until the next call to strerror.
Writing to the storage causes undefined behavior. */
+libc_freeres_ptr (static char *buf);
+
char *
strerror (errnum)
int errnum;
{
- static char buf[1024];
- return __strerror_r (errnum, buf, sizeof buf);
+ char *ret = __strerror_r (errnum, NULL, 0);
+ int saved_errno;
+
+ if (__builtin_expect (ret != NULL, 1))
+ return ret;
+ saved_errno = errno;
+ if (buf == NULL)
+ buf = malloc (1024);
+ __set_errno (saved_errno);
+ if (buf == NULL)
+ return _("Unknown error");
+ return __strerror_r (errnum, buf, 1024);
}
}
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
+ /* Not libc_freeres_ptr, since buf is a macro. */
free (buf);
}
-text_set_element (__libc_subfreeres, free_mem);
return 0;
}
#ifdef _LIBC
-static void
-free_mem (void)
+libc_freeres_fn (free_mem)
{
/* Remove all traces. */
clearenv ();
__tdestroy (known_values, free);
known_values = NULL;
}
-text_set_element (__libc_subfreeres, free_mem);
-
# undef setenv
# undef unsetenv
-/* Copyright (C) 1991, 92, 93, 96, 97, 98, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,96,97,98,2000,2002 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
int save, int *dostat) internal_function;
-static char *getttyname_name;
+libc_freeres_ptr (static char *getttyname_name);
static char *
internal_function
return name;
}
-
-
-static void
-free_mem (void)
-{
- free (getttyname_name);
-}
-text_set_element (__libc_subfreeres, free_mem);
aiocbp->aiocb64.aio_offset));
else
aiocbp->aiocb.__return_value =
- TEMP_FAILURE_RETRY (pwrite (fildes, (const void *)
+ TEMP_FAILURE_RETRY (__libc_pwrite (fildes, (const void *)
aiocbp->aiocb.aio_buf,
aiocbp->aiocb.aio_nbytes,
aiocbp->aiocb.aio_offset));
/* Free allocated resources. */
-static void
-__attribute__ ((unused))
-free_res (void)
+libc_freeres_fn (free_res)
{
size_t row;
free (pool);
}
-text_set_element (__libc_subfreeres, free_res);
/* Add newrequest to the runlist. The __abs_prio flag of newrequest must
static const char path_proc[] = "/proc";
/* Actual mount point of /proc filesystem. */
-static char *mount_proc;
+libc_freeres_ptr (static char *mount_proc);
/* Determine the path to the /proc filesystem if available. */
static const char *
return phys_pages_info ("MemFree: %ld kB");
}
weak_alias (__get_avphys_pages, get_avphys_pages)
-
-
-static void
-free_mem (void)
-{
- free (mount_proc);
-}
-text_set_element (__libc_subfreeres, free_mem);
}
-static void __attribute__ ((unused))
-freeit (void)
+/* Make sure the table is freed if we want to free everything before
+ exiting. */
+libc_freeres_fn (freeit)
{
if (mountpoint.dir != defaultdir)
free (mountpoint.dir);
}
-
-
-/* Make sure the table is freed if we want to free everything before
- exiting. */
-text_set_element (__libc_subfreeres, freeit);
internal_function;
-static char *getttyname_name;
+libc_freeres_ptr (static char *getttyname_name);
static char *
internal_function
/* Static buffer in `ttyname'. */
-static char *ttyname_buf;
+libc_freeres_ptr (static char *ttyname_buf);
/* Return the pathname of the terminal FD is open on, or NULL on errors.
return name;
}
-
-
-static void
-free_mem (void)
-{
- free (ttyname_buf);
- free (getttyname_name);
-}
-text_set_element (__libc_subfreeres, free_mem);
static void compute_tzname_max (size_t) internal_function;
static size_t num_transitions;
-static time_t *transitions;
+libc_freeres_ptr (static time_t *transitions);
static unsigned char *type_idxs;
static size_t num_types;
static struct ttinfo *types;
}
while (++p < &zone_names[chars]);
}
-\f
-/* This function is only called when we are checking for memory leaks. */
-static void
-freeres (void)
-{
- if (transitions != NULL)
- free ((void *) transitions);
-}
-
-/* Make sure all allocated data is freed before exiting. */
-text_set_element (__libc_subfreeres, freeres);
}
-static void
-free_mem (void)
+libc_freeres_fn (free_mem)
{
while (tzstring_list != NULL)
{
free (old_tz);
old_tz = NULL;
}
-text_set_element (__libc_subfreeres, free_mem);