]> sourceware.org Git - glibc.git/commitdiff
* include/libc-symbols.h (__libc_freeres_fn_section, libc_freeres_fn):
authorRoland McGrath <roland@gnu.org>
Fri, 1 Nov 2002 20:44:15 +0000 (20:44 +0000)
committerRoland McGrath <roland@gnu.org>
Fri, 1 Nov 2002 20:44:15 +0000 (20:44 +0000)
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.

51 files changed:
ChangeLog
Makerules
crypt/md5-crypt.c
elf/dl-close.c
elf/dl-libc.c
grp/fgetgrent.c
iconv/gconv_cache.c
iconv/gconv_conf.c
iconv/gconv_db.c
iconv/gconv_dl.c
include/libc-symbols.h
inet/getnetgrent.c
inet/rcmd.c
inet/rexec.c
intl/dcigettext.c
intl/finddomain.c
intl/localealias.c
locale/loadarchive.c
locale/setlocale.c
login/getutent.c
login/getutid.c
login/getutline.c
malloc/mtrace.c
malloc/obstack.c
malloc/set-freeres.c
misc/efgcvt.c
misc/fstab.c
misc/mntent.c
nss/getXXbyYY.c
nss/getXXent.c
nss/nsswitch.c
posix/regcomp.c
pwd/fgetpwent.c
resolv/gai_misc.c
resolv/ns_print.c
resolv/nsap_addr.c
resolv/res_hconf.c
shadow/fgetspent.c
stdio-common/printf-parse.h
stdio-common/reg-printf.c
stdlib/fmtmsg.c
string/strerror.c
sunrpc/clnt_perr.c
sysdeps/generic/setenv.c
sysdeps/posix/ttyname.c
sysdeps/pthread/aio_misc.c
sysdeps/unix/sysv/linux/getsysstats.c
sysdeps/unix/sysv/linux/shm_open.c
sysdeps/unix/sysv/linux/ttyname.c
time/tzfile.c
time/tzset.c

index 271e45130129b9ad8e8301fcb5f081fa6a1f417d..8226c644e2c2723ee85ff7d7245b8bb16250c223 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,109 @@
+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):
index d66feb5b75bb076d223840c3b99425e41e6fc22c..071352db516fd63f1dc79ea03191cb2359a36f93 100644 (file)
--- a/Makerules
+++ b/Makerules
@@ -447,7 +447,7 @@ $(build-shlib-helper) \
          $(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)
@@ -548,6 +548,7 @@ ifeq ($(elf),yes)
 $(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 \
index 0f7f3ecce3ed8cba725f1f015a656f772cf2ec7c..8cd23e3fa666419ddaba39bdc3de90fd2efdedf6 100644 (file)
@@ -1,5 +1,5 @@
 /* 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.
 
@@ -233,8 +233,10 @@ __md5_crypt_r (key, salt, buffer, buflen)
   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)
@@ -261,10 +263,11 @@ __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
index 094db533ddfd9735dea40d3144bcb4ea765f7e88..632f8ba9fcf9c5076df5c3dbc5cb3a0de57667a8 100644 (file)
@@ -247,6 +247,11 @@ _dl_close (void *_map)
   _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)
@@ -286,6 +291,30 @@ _dl_close (void *_map)
                                     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
 
@@ -363,11 +392,15 @@ _dl_close (void *_map)
     }
 
 #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.  */
@@ -424,8 +457,7 @@ free_slotinfo (struct dtv_slotinfo_list *elemp)
 #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)
@@ -453,4 +485,3 @@ free_mem (void)
     GL(dl_tls_dtv_slotinfo_list)->next = NULL;
 #endif
 }
-text_set_element (__libc_subfreeres, free_mem);
index 938b5d707dc99e54157b465aed6f0f8173287d1d..d69e49f3599e0feadb0882c35fbc15860313bc5f 100644 (file)
@@ -123,8 +123,7 @@ __libc_dlclose (void *__map)
 }
 
 
-static void
-free_mem (void)
+libc_freeres_fn (free_mem)
 {
   struct link_map *l;
   struct r_search_path_elem *d;
@@ -154,4 +153,3 @@ free_mem (void)
        }
     }
 }
-text_set_element (__libc_subfreeres, free_mem);
index a004aabdf1181f9c483d32f0ebd68e41865f054d..684018c4293def75342247c1be07ab44fe21c8c4 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -26,7 +26,7 @@
 /* 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 *
@@ -83,13 +83,3 @@ fgetgrent (FILE *stream)
 
   return result;
 }
-
-
-/* Free all resources if necessary.  */
-static void __attribute__ ((unused))
-free_mem (void)
-{
-  free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
index f7dca0285a02da97cf5c3a8d34ab3f3985bac678..8f92cbaf6791345e8406acd13dfada87faa9b594 100644 (file)
@@ -445,8 +445,7 @@ __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
 
 
 /* Free all resources if necessary.  */
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
 {
   if (cache_malloced)
     free (gconv_cache);
@@ -455,5 +454,3 @@ free_mem (void)
     __munmap (gconv_cache, cache_size);
 #endif
 }
-
-text_set_element (__libc_subfreeres, free_mem);
index 8c2f4b014e9577d3445f9216fd113383376c9a71..cd5055c303e70cfa2bc75a01147e7cdef812d539 100644 (file)
@@ -597,11 +597,8 @@ __gconv_read_conf (void)
 
 
 /* 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);
index 25b06d07e4ad9afd89af8859d2c8a1a5f4a52573..70c33df16d158458d5f7bcc345199d756249b9de 100644 (file)
@@ -778,8 +778,7 @@ free_modules_db (struct gconv_module *node)
 
 
 /* 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);
@@ -790,5 +789,3 @@ free_mem (void)
   if (known_derivations != NULL)
     __tdestroy (known_derivations, free_derivation);
 }
-
-text_set_element (__libc_subfreeres, free_mem);
index 990338f0707e3dd1c31d95b34ef2ff59ae4f39f8..ff90a54b41435ed82efd9b745e0a9374286d9110 100644 (file)
@@ -203,12 +203,10 @@ do_release_all (void *nodep)
   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
index 69fe729d73f6148ae564a8fa874ae33752e8ed93..f47a849a753ffb5877a65972d211d1ffafed1d8a 100644 (file)
 /* 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) \
index d464c10cdea59be9b49b2bc4e2f6983c6bc18ca7..07634daef21dff6ef600dfcf609309e8fcfa80cf 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -21,8 +21,8 @@
 #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
 
@@ -48,15 +48,3 @@ getnetgrent (char **hostp, char **userp, char **domainp)
 
   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);
index 08d9337431cb9ff973abee1b5423fc7492a2e90a..eed5ed389e4991ea34993fa0dbd316df5de6d29d 100644 (file)
@@ -101,7 +101,7 @@ int iruserok (u_int32_t raddr, int superuser, const char *ruser,
 
 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)
@@ -153,11 +153,21 @@ 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;
index 8f6190a83439ade6a63fe2906f9a8ff15e649a1b..c6b432a6f8afb3c846184be884486f03ff7089a7 100644 (file)
@@ -45,7 +45,7 @@ static char sccsid[] = "@(#)rexec.c   8.1 (Berkeley) 6/4/93";
 #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)
@@ -79,13 +79,15 @@ 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);
index 42d39a17717373ced1b636ce3d07bedf60cd7c82..80c71efbc45a942efadf0d1795d3e81e7f623e58 100644 (file)
@@ -1124,8 +1124,7 @@ mempcpy (dest, src, n)
 #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;
 
@@ -1155,6 +1154,4 @@ free_mem (void)
       free (old);
     }
 }
-
-text_set_element (__libc_subfreeres, free_mem);
 #endif
index e0e11f0b7e6074f7e105f9421c4f5950eb3ffc68..1031e4d5b19a080657c4557ea20f0514bd0673b9 100644 (file)
@@ -168,8 +168,7 @@ _nl_find_domain (dirname, locale, domainname, domainbinding)
 
 
 #ifdef _LIBC
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
 {
   struct loaded_l10nfile *runp = _nl_loaded_domains;
 
@@ -183,6 +182,4 @@ free_mem (void)
       free (here);
     }
 }
-
-text_set_element (__libc_subfreeres, free_mem);
 #endif
index 0afe98134b34a1c121070ebbf4899da364e5d58c..f5d4e57dc31bdd6c59a14ba01f175ba93bea6572 100644 (file)
@@ -117,10 +117,14 @@ struct alias_map
 };
 
 
-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;
 
@@ -371,19 +375,6 @@ extend_alias_table ()
 }
 
 
-#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;
index aa19dbd5f8eb8cca72c2b5f9ff52d9583e6675d3..dbb4d7afd52a04e5c2e516345a8593c3f3802273 100644 (file)
@@ -493,7 +493,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
   return lia->data[category];
 }
 
-void
+void __libc_freeres_fn_section
 _nl_archive_subfreeres (void)
 {
   struct locale_in_archive *lia;
index 56a875e378981d73767ed223dd62a63e53f8800a..50c752826c9e1ff9bbb248d9bdcc6d9922db3cc1 100644 (file)
@@ -463,8 +463,7 @@ free_category (int category,
     }
 }
 
-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
@@ -494,4 +493,3 @@ free_mem (void)
      not called _nl_unload_locale on them above.  */
   _nl_archive_subfreeres ();
 }
-text_set_element (__libc_subfreeres, free_mem);
index 735cd9334abdca94d1726d6a951d58dad99d3f5d..561f17f4d993c49aecca7b0b7699cf0dd6b9195d 100644 (file)
@@ -1,4 +1,4 @@
-/* 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 *
@@ -30,7 +30,14 @@ __getutent (void)
 {
   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;
index beeedb374961db8953deb559743a2cb64e068ff0..3d022e405d67503de6c38905f593557453e628af 100644 (file)
@@ -1,4 +1,4 @@
-/* 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;
index d1704ec31c854e4763e212a2a2ed912b980f7047..7618064d0042c091eb6ccfd96cecf798018a1574 100644 (file)
@@ -1,4 +1,4 @@
-/* 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 *
@@ -30,7 +30,13 @@ __getutline (const struct utmp *line)
 {
   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;
index d9960bdaf3dbab6d63d26990d8f87a1cc8ff5e2b..c369ab577c8eefd5a7bab7412b624cd62301801c 100644 (file)
@@ -50,7 +50,7 @@
 
 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);
 
@@ -237,7 +237,7 @@ tr_reallochook (ptr, size, caller)
 /* 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.  */
@@ -274,6 +274,10 @@ mtrace ()
 #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)
        {
@@ -285,6 +289,7 @@ mtrace ()
              __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;
@@ -303,6 +308,8 @@ mtrace ()
            }
 #endif
        }
+      else
+       free (mtb);
     }
 }
 
index 5c5e8b09d8de0516c92e337a06c959ac73bb947d..2f5ff628f78707011c885ffc6c01cfda6bd9457c 100644 (file)
@@ -418,6 +418,10 @@ _obstack_free (h, obj)
 
 /* This function is used from ANSI code.  */
 
+#ifdef _LIBC
+strong_alias (_obstack_free, obstack_free)
+#else
+
 void
 obstack_free (h, obj)
      struct obstack *h;
@@ -449,6 +453,7 @@ obstack_free (h, obj)
     /* obj is not in any of the chunks! */
     abort ();
 }
+#endif
 \f
 int
 _obstack_memory_used (h)
index dfbd7b5908782297ed8faf6e26a97a4563825e14..67488a821489b9ae4f1df3c44ff600db42575782 100644 (file)
@@ -27,7 +27,9 @@
 
 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
@@ -36,11 +38,17 @@ __libc_freeres (void)
 
   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)
index bc4bf91d0240c7330ea6a7f7ea738f27505adffc..915d00dfd56e3f7b635a4113a5ea1f6eafe2dbea 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -57,7 +57,7 @@
 
 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)
@@ -102,13 +102,3 @@ APPEND (FUNC_PREFIX, gcvt) (value, ndigit, buf)
   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);
index 754ea1343ab57701a309fbed142ae3927b696ee8..b434203a868f7d18104f008e27e02e71d7fa2079 100644 (file)
@@ -180,9 +180,7 @@ fstab_convert (struct fstab_state *state)
 
 /* 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;
 
@@ -190,5 +188,3 @@ fstab_free (void)
   if (buffer != NULL)
     free ((void *) buffer);
 }
-
-text_set_element (__libc_subfreeres, fstab_free);
index d7cff3c302df2a1ee16d098196df27390e37fd9a..6e9795a1eac11feb31f419015b78ac47bb5eba8b 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -24,7 +24,7 @@
 /* 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
@@ -52,15 +52,3 @@ getmntent (FILE *stream)
 
   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);
index ee6f640002bfe9b91cc95755ae8ef880b769ce90..a9f1cfd5c8522a13580d050714c7550ab993add1 100644 (file)
@@ -86,7 +86,7 @@ extern int INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf,
 __libc_lock_define_initialized (static, lock);
 
 /* This points to the static buffer used.  */
-static char *buffer;
+libc_freeres_ptr (static char *buffer);
 
 
 LOOKUP_TYPE *
@@ -162,13 +162,3 @@ done:
 
   return result;
 }
-
-
-/* Free all resources if necessary.  */
-static void __attribute__ ((unused))
-free_mem (void)
-{
-  free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
index d4a29ce46a14d9fe5070367cb31e38dc4718a242..ebe6fff5f0eaf33b30c256a82ab180d56e40a6b4 100644 (file)
@@ -63,7 +63,7 @@ extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer,
 __libc_lock_define_initialized (static, lock);
 
 /* This points to the static buffer used.  */
-static char *buffer;
+libc_freeres_ptr (static char *buffer);
 
 
 LOOKUP_TYPE *
@@ -87,13 +87,3 @@ GETFUNC_NAME (void)
   __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);
index ca411b2cdc6fdef13092de59341265b16ab8399a..1b3bb23e0b6700e39d7caf3446bf35689aefc6e7 100644 (file)
@@ -697,8 +697,7 @@ nss_new_service (name_database *database, const char *name)
 
 
 /* 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;
@@ -745,5 +744,3 @@ free_mem (void)
 
   free (top);
 }
-
-text_set_element (__libc_subfreeres, free_mem);
index 9bb06aa7bf99750fa2d80b62e4b0a592a93b5f6e..14147804f49c0576c0c3176d4d8b68728c03cffd 100644 (file)
@@ -696,12 +696,10 @@ re_comp (s)
 }
 
 #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 */
index 89f7996e3c1bef1d300c467eb90047929f38efa1..ad9ce631175e2ec7130eb0d4dbc52543e76c29e8 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -26,7 +26,7 @@
 /* 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 *
@@ -83,13 +83,3 @@ fgetpwent (FILE *stream)
 
   return result;
 }
-
-
-/* Free all resources if necessary.  */
-static void __attribute__ ((unused))
-free_mem (void)
-{
-  free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
index b89abf984abb16955c3059442b8a3b7d0710bb07..b3334f38efd4ff937808d0e1bf368eb283b61667 100644 (file)
@@ -410,9 +410,7 @@ handle_requests (void *arg)
 
 
 /* Free allocated resources.  */
-static void
-__attribute__ ((unused))
-free_res (void)
+libc_freeres_fn (free_res)
 {
   size_t row;
 
@@ -421,4 +419,3 @@ free_res (void)
 
   free (pool);
 }
-text_set_element (__libc_subfreeres, free_res);
index 7a2ef70efc22f9280ffeb78ab3f41a8653f693de..12b2e67ea66d1b3f3444c10bb9177d714a591167 100644 (file)
@@ -309,7 +309,9 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
                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));
index b3f2f77cafd6fc63b0f24ceff210fd7b2f3a8b7d..7041e5282ebae4ed3cc9bf91374d0ce24258aff8 100644 (file)
@@ -70,7 +70,7 @@ char *
 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)
index 132dda7599e64d2a3cacdf04642a6bf7c54023f9..40afeb0b946282b55e76ea6e520bf7a86b1200a9 100644 (file)
@@ -489,6 +489,7 @@ _res_hconf_init (void)
 
 
 /* List of known interfaces.  */
+libc_freeres_ptr (
 static struct netaddr
 {
   int addrtype;
@@ -500,7 +501,7 @@ static struct netaddr
       u_int32_t        mask;
     } ipv4;
   } u;
-} *ifaddrs;
+} *ifaddrs);
 
 /* We need to protect the dynamic buffer handling.  */
 __libc_lock_define_initialized (static, lock);
@@ -657,13 +658,3 @@ _res_hconf_trim_domains (struct hostent *hp)
   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);
index 2b24bd85347a8fb890054ea4da3bbec552cd63f8..63f16a10dba123885e88fb6d3c35ca6fac41808f 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -29,7 +29,7 @@
 /* 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 *
@@ -86,13 +86,3 @@ fgetspent (FILE *stream)
 
   return result;
 }
-
-
-/* Free all resources if necessary.  */
-static void __attribute__ ((unused))
-free_mem (void)
-{
-  free (buffer);
-}
-
-text_set_element (__libc_subfreeres, free_mem);
index 78811701bbe7613436cb69db4b1b8192b3deba61..eff28166078c23db61df6b5b417a6b86e9de61cb 100644 (file)
@@ -117,7 +117,7 @@ find_spec (const UCHAR_T *format, mbstate_t *ps)
 
 
 /* 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;
 
 
@@ -354,7 +354,7 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
 
   /* 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
index fe496339326394f296140119626077a16cb1f030..c42040ec3a956a8f573a977fc710d2a86b4a4f03 100644 (file)
 #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,
@@ -43,9 +41,18 @@ __register_printf_function (spec, converter, arginfo)
       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;
 }
index 660df1fdcbb5a222fd4cf1c9a400e7084cb8bfb6..37c641c7ef91154387cb3e98a2bf512e7f02060d 100644 (file)
@@ -390,8 +390,7 @@ addseverity (int severity, const char *string)
 }
 
 
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
 {
   struct severity_info *runp = severity_list;
 
@@ -407,4 +406,3 @@ free_mem (void)
     else
       runp = runp->next;
 }
-text_set_element (__libc_subfreeres, free_mem);
index 8a54a38ee0f4f6a7c4a44ef7f2ccae791a8180b1..5d829d0bf0e2da57b5122fa244ded979ad8927ed 100644 (file)
@@ -1,4 +1,4 @@
-/* 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);
 }
index ad96e4a0fefafc5ff2d258240f9db0a86655d867..4b34289a88590368998b0ebe433098561828cc95 100644 (file)
@@ -413,9 +413,8 @@ auth_errmsg (enum auth_stat stat)
 }
 
 
-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);
index e5799e529d920a6286351b7d0524e5f55be666ae..e7fd49228c62cc698c8f4a1fdd05172fa00b4c7c 100644 (file)
@@ -323,8 +323,7 @@ clearenv ()
   return 0;
 }
 #ifdef _LIBC
-static void
-free_mem (void)
+libc_freeres_fn (free_mem)
 {
   /* Remove all traces.  */
   clearenv ();
@@ -333,8 +332,6 @@ free_mem (void)
   __tdestroy (known_values, free);
   known_values = NULL;
 }
-text_set_element (__libc_subfreeres, free_mem);
-
 
 # undef setenv
 # undef unsetenv
index e5c3b3fbe0b00472e83717a5d9416325fde0ce40..b7a5d85661df353f4c63801697c8906d2423c56e 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -32,7 +32,7 @@ static char *getttyname (int fd, dev_t mydev, ino_t myino,
                         int save, int *dostat) internal_function;
 
 
-static char *getttyname_name;
+libc_freeres_ptr (static char *getttyname_name);
 
 static char *
 internal_function
@@ -134,11 +134,3 @@ ttyname (fd)
 
   return name;
 }
-
-
-static void
-free_mem (void)
-{
-  free (getttyname_name);
-}
-text_set_element (__libc_subfreeres, free_mem);
index b0432e6e0e10c76a8483ee2fa980d8ca0c349fc6..78cf764837f9f8ede25c3468b8cdfebdfa81043e 100644 (file)
@@ -530,7 +530,7 @@ handle_fildes_io (void *arg)
                                                  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));
@@ -665,9 +665,7 @@ handle_fildes_io (void *arg)
 
 
 /* Free allocated resources.  */
-static void
-__attribute__ ((unused))
-free_res (void)
+libc_freeres_fn (free_res)
 {
   size_t row;
 
@@ -676,7 +674,6 @@ free_res (void)
 
   free (pool);
 }
-text_set_element (__libc_subfreeres, free_res);
 
 
 /* Add newrequest to the runlist. The __abs_prio flag of newrequest must
index eaacf3727c6a45a489c29ad3f75e9e31fbf0e34f..55ef5b661a701815485420c65304ab196415b705 100644 (file)
@@ -38,7 +38,7 @@
 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 *
@@ -319,11 +319,3 @@ __get_avphys_pages ()
   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);
index a96df2427c44cda2ef6fc5ab2cfae7ce0b281af2..b118533dca13601787bd7691a8a5e97f863db4aa 100644 (file)
@@ -226,14 +226,10 @@ shm_unlink (const char *name)
 }
 
 
-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);
index f8e6e925a44ef1b254bca0450542027bacfe69e6..68d24f195ec294a6dcb42283b8659ee8e3f2f992 100644 (file)
@@ -38,7 +38,7 @@ static char *getttyname (const char *dev, dev_t mydev,
      internal_function;
 
 
-static char *getttyname_name;
+libc_freeres_ptr (static char *getttyname_name);
 
 static char *
 internal_function
@@ -103,7 +103,7 @@ getttyname (const char *dev, dev_t mydev, ino64_t myino, int save, int *dostat)
 
 
 /* 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.
@@ -186,12 +186,3 @@ ttyname (int fd)
 
   return name;
 }
-
-
-static void
-free_mem (void)
-{
-  free (ttyname_buf);
-  free (getttyname_name);
-}
-text_set_element (__libc_subfreeres, free_mem);
index 5c2b28d582bf485920bf5a669b2f6d5041d9d968..24ef18f94127487d637c312cf63fddb49ee50362 100644 (file)
@@ -49,7 +49,7 @@ static struct ttinfo *find_transition (time_t timer) internal_function;
 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;
@@ -553,14 +553,3 @@ compute_tzname_max (size_t chars)
     }
   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);
index c9a9783b2d3576f8dc9893afb7193d4bfd78032c..02940589f7427718d15dc29a33b397065248bcbe 100644 (file)
@@ -624,8 +624,7 @@ __tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
 }
 
 
-static void
-free_mem (void)
+libc_freeres_fn (free_mem)
 {
   while (tzstring_list != NULL)
     {
@@ -637,4 +636,3 @@ free_mem (void)
   free (old_tz);
   old_tz = NULL;
 }
-text_set_element (__libc_subfreeres, free_mem);
This page took 0.11849 seconds and 5 git commands to generate.