[memprof: 44/76] process_find_line: Clarify who is owning the returned pointer
- From: Holger Hans Peter Freyther <hfreyther src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [memprof: 44/76] process_find_line: Clarify who is owning the returned pointer
- Date: Sun, 13 Jun 2010 03:41:56 +0000 (UTC)
commit 2936349b0d6c6743df9a99f7aef7075f01059d54
Author: Holger Hans Peter Freyther <zecke selfish org>
Date: Sun Oct 25 09:15:59 2009 +0100
process_find_line: Clarify who is owning the returned pointer
Only free the pointer if it was allocated locally
and not if it was coming out of process_find_line. This
is fixing a crash in the leak finding.
* src/main.c:
(leak_block_selection_changed):
(leaks_fill):
(leak_stack_run_command):
* src/process.c:
(process_find_line):
src/main.c | 14 +++++++-------
src/process.c | 4 ++++
2 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 787e062..f4e08b3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -622,7 +622,7 @@ leak_block_selection_changed (GtkTreeSelection *selection,
if (!process_find_line (pwin->process, stack->address,
&filename, &functionname, &line)) {
/* 0x3f == '?' -- suppress trigraph warnings */
- functionname = g_strdup ("(\x3f\x3f\x3f)");
+ functionname = "(\x3f\x3f\x3f)";
filename = "(\x3f\x3f\x3f)";
line = 0;
}
@@ -655,6 +655,7 @@ leaks_fill (ProcessWindow *pwin)
tmp_list = pwin->leaks;
while (tmp_list) {
const char *filename;
+ gboolean free_function = FALSE;
char *functionname = NULL;
GtkTreeIter iter;
@@ -673,7 +674,6 @@ leaks_fill (ProcessWindow *pwin)
for (tmp_list = skip_funcs; tmp_list != NULL; tmp_list = tmp_list->next) {
if (!strcmp (functionname, tmp_list->data)) {
- free (functionname);
functionname = NULL;
break;
}
@@ -688,7 +688,6 @@ leaks_fill (ProcessWindow *pwin)
regcomp (®ex, tmp_list->data, 0);
if (!regexec (®ex, functionname, 0, NULL, 0)) {
- free (functionname);
functionname = NULL;
regfree (®ex);
break;
@@ -701,8 +700,10 @@ leaks_fill (ProcessWindow *pwin)
if (functionname)
break;
}
- if (!functionname)
+ if (!functionname) {
+ free_function = TRUE;
functionname = g_strdup ("(\x3f\x3f\x3f)");
+ }
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
@@ -712,7 +713,8 @@ leaks_fill (ProcessWindow *pwin)
LEAK_BLOCK_BLOCK, block,
-1);
- g_free (functionname);
+ if (free_function)
+ g_free (functionname);
tmp_list = tmp_list->next;
}
@@ -762,8 +764,6 @@ leak_stack_run_command (ProcessWindow *pwin, Block *block, int frame)
p++;
}
- free (functionname);
-
cmdline = g_strdup_printf ("/bin/sh -c %s", command->str);
if (!g_spawn_command_line_async (cmdline, &err)) {
diff --git a/src/process.c b/src/process.c
index 9128931..70a0a2f 100644
--- a/src/process.c
+++ b/src/process.c
@@ -243,6 +243,10 @@ process_locate_symbol (MPProcess *process, gsize addr)
return bin_symbol_get_name (map->binfile, symbol);
}
+/**
+ * The string assigned to functionname is owned/shared
+ * by the system and must not be freed.
+ */
gboolean
process_find_line (MPProcess *process, void *address,
const char **filename, char **functionname,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]