aboutsummaryrefslogtreecommitdiff
path: root/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'malloc')
-rw-r--r--malloc/mtrace.c11
-rw-r--r--malloc/obstack.c5
-rw-r--r--malloc/set-freeres.c10
3 files changed, 23 insertions, 3 deletions
diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index d9960bdaf3..c369ab577c 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -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);
}
}
diff --git a/malloc/obstack.c b/malloc/obstack.c
index 5c5e8b09d8..2f5ff628f7 100644
--- a/malloc/obstack.c
+++ b/malloc/obstack.c
@@ -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
int
_obstack_memory_used (h)
diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c
index dfbd7b5908..67488a8214 100644
--- a/malloc/set-freeres.c
+++ b/malloc/set-freeres.c
@@ -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)