2002-10-30 Jakub Jelinek <jakub@redhat.com>
authorroland <roland>
Fri, 1 Nov 2002 20:43:42 +0000 (20:43 +0000)
committerroland <roland>
Fri, 1 Nov 2002 20:43:42 +0000 (20:43 +0000)
* 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.

malloc/mtrace.c

index d9960bd..c369ab5 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);
     }
 }