From 0513ed87e82c202cfec133a177fbb89334b8d695 Mon Sep 17 00:00:00 2001 From: Soren Sandmann Date: Thu, 2 Nov 2006 08:33:35 +0000 Subject: [PATCH] Valgrind: 2006-11-02 Soren Sandmann Valgrind: * binparser.c (bin_parser_free): Add this function * elfparser.c (elf_parser_free): Call bin_parser_free() * sysprof.c (compute_text_width, add_text): Plug leaks * collector.c (add_trace_to_stash): Copy n_addresses to a stack variable instead of reading it out of the mmap'ed area all the time. (That way if there is an overrun, we won't write too much into the address array). --- ChangeLog | 15 +++++++++++++++ binparser.c | 6 ++++++ collector.c | 15 +++++++++++---- elfparser.c | 2 ++ sysprof.c | 6 ++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0888e138..2b7515ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2006-11-02 Soren Sandmann + + Valgrind: + + * binparser.c (bin_parser_free): Add this function + + * elfparser.c (elf_parser_free): Call bin_parser_free() + + * sysprof.c (compute_text_width, add_text): Plug leaks + + * collector.c (add_trace_to_stash): Copy n_addresses to a stack + variable instead of reading it out of the mmap'ed area all the + time. (That way if there is an overrun, we won't write too much + into the address array). + 2006-10-26 Soren Sandmann * module/sysprof-module.h (struct SysprofStackTrace): Increase the diff --git a/binparser.c b/binparser.c index 2fba501c..c947aff6 100644 --- a/binparser.c +++ b/binparser.c @@ -54,6 +54,12 @@ bin_parser_new (const guchar *data, return parser; } +void +bin_parser_free (BinParser *parser) +{ + g_free (parser); +} + static GQueue * read_varargs (va_list args, const char * name, diff --git a/collector.c b/collector.c index dae6e94e..8bf737a6 100644 --- a/collector.c +++ b/collector.c @@ -91,10 +91,13 @@ add_trace_to_stash (const SysprofStackTrace *trace, int i; gulong *addrs; Process *process = process_get_from_pid (trace->pid); + int n_addresses; - addrs = g_new (gulong, trace->n_addresses + 1); + n_addresses = trace->n_addresses; - for (i = 0; i < trace->n_addresses; ++i) + addrs = g_new (gulong, n_addresses + 1); + + for (i = 0; i < n_addresses; ++i) { process_ensure_map (process, trace->pid, (gulong)trace->addresses[i]); @@ -105,7 +108,7 @@ add_trace_to_stash (const SysprofStackTrace *trace, addrs[i] = (gulong)process; stack_stash_add_trace ( - stash, addrs, trace->n_addresses + 1, 1); + stash, addrs, n_addresses + 1, 1); g_free (addrs); } @@ -324,7 +327,11 @@ unique_dup (GHashTable *unique_symbols, const char *sym) static char * lookup_symbol (Process *process, gpointer address, GHashTable *unique_symbols) { - const char *sym = process_lookup_symbol (process, (gulong)address); + const char *sym; + + g_assert (process); + + sym = process_lookup_symbol (process, (gulong)address); return unique_dup (unique_symbols, sym); } diff --git a/elfparser.c b/elfparser.c index 7d9447b5..500b52fd 100644 --- a/elfparser.c +++ b/elfparser.c @@ -315,6 +315,8 @@ elf_parser_free (ElfParser *parser) if (parser->file) g_mapped_file_free (parser->file); + + bin_parser_free (parser->parser); g_free (parser); } diff --git a/sysprof.c b/sysprof.c index fdf30fae..b88fb4b3 100644 --- a/sysprof.c +++ b/sysprof.c @@ -1066,6 +1066,8 @@ compute_text_width (GtkTreeView *view, get_data (view, iter, &name, NULL, NULL); *width = MAX (g_utf8_strlen (name, -1) + get_indent (path), *width); + + g_free (name); } typedef struct @@ -1106,6 +1108,8 @@ add_text (GtkTreeView *view, g_string_append_c (info->text, ' '); g_string_append_printf (info->text, "%-*s %6.2f %6.2f\n", info->max_width - indent, name, self, cumulative); + + g_free (name); } static void @@ -1601,6 +1605,8 @@ main (int argc, * - caches too much memory * - is not actually faster */ +#endif +#if 0 g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE); #endif