* 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.
$(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
-/* 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);
-/* 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);
};
-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;
/* 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);
/* 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);
-/* 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);
/* 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;
}
-/* 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);
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);
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);