* [PATCH v1 0/2] Fix leak sanitizer warnings in perf top
@ 2023-06-07 5:01 Ian Rogers
2023-06-07 5:01 ` [PATCH v1 1/2] perf annotate: Fix parse_objdump_line memory leak Ian Rogers
2023-06-07 5:01 ` [PATCH v1 2/2] perf top: Add exit routine for main thread Ian Rogers
0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2023-06-07 5:01 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Andres Freund, Huacai Chen,
linux-perf-users, linux-kernel
With these two patches perf top/report/script will largely run without
leak sanitizer warnings.
Ian Rogers (2):
perf annotate: Fix parse_objdump_line memory leak
perf top: Add exit routine for main thread
tools/perf/builtin-top.c | 11 ++++++++++-
tools/perf/util/annotate.c | 3 ++-
2 files changed, 12 insertions(+), 2 deletions(-)
--
2.41.0.rc0.172.g3f132b7071-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v1 1/2] perf annotate: Fix parse_objdump_line memory leak
2023-06-07 5:01 [PATCH v1 0/2] Fix leak sanitizer warnings in perf top Ian Rogers
@ 2023-06-07 5:01 ` Ian Rogers
2023-06-07 5:01 ` [PATCH v1 2/2] perf top: Add exit routine for main thread Ian Rogers
1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2023-06-07 5:01 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Andres Freund, Huacai Chen,
linux-perf-users, linux-kernel
fileloc is used to hold a previous line, before overwriting it ensure
the previous contents is freed. Free the storage once done in
symbol__disassemble.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/annotate.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b708bbc49c9e..fc5f44535ebe 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1524,6 +1524,7 @@ static int symbol__parse_objdump_line(struct symbol *sym,
/* /filename:linenr ? Save line number and ignore. */
if (regexec(&file_lineno, parsed_line, 2, match, 0) == 0) {
*line_nr = atoi(parsed_line + match[1].rm_so);
+ free(*fileloc);
*fileloc = strdup(parsed_line);
return 0;
}
@@ -1572,7 +1573,6 @@ static int symbol__parse_objdump_line(struct symbol *sym,
}
annotation_line__add(&dl->al, ¬es->src->source);
-
return 0;
}
@@ -2114,6 +2114,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
nline++;
}
free(line);
+ free(fileloc);
err = finish_command(&objdump_process);
if (err)
--
2.41.0.rc0.172.g3f132b7071-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v1 2/2] perf top: Add exit routine for main thread
2023-06-07 5:01 [PATCH v1 0/2] Fix leak sanitizer warnings in perf top Ian Rogers
2023-06-07 5:01 ` [PATCH v1 1/2] perf annotate: Fix parse_objdump_line memory leak Ian Rogers
@ 2023-06-07 5:01 ` Ian Rogers
1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2023-06-07 5:01 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Andres Freund, Huacai Chen,
linux-perf-users, linux-kernel
Add exit_process_thread that reverses init_process_thread. This avoids
leak sanitizer reporting memory leaks.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-top.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 99010dfa5760..c363c04e16df 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -392,7 +392,7 @@ static void prompt_percent(int *target, const char *msg)
static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)
{
- char *buf = malloc(0), *p;
+ char *buf = NULL, *p;
struct hist_entry *syme = top->sym_filter_entry, *n, *found = NULL;
struct hists *hists = evsel__hists(top->sym_evsel);
struct rb_node *next;
@@ -1227,6 +1227,14 @@ static void init_process_thread(struct perf_top *top)
cond_init(&top->qe.cond);
}
+static void exit_process_thread(struct perf_top *top)
+{
+ ordered_events__free(&top->qe.data[0]);
+ ordered_events__free(&top->qe.data[1]);
+ mutex_destroy(&top->qe.mutex);
+ cond_destroy(&top->qe.cond);
+}
+
static int __cmd_top(struct perf_top *top)
{
struct record_opts *opts = &top->record_opts;
@@ -1357,6 +1365,7 @@ static int __cmd_top(struct perf_top *top)
cond_signal(&top->qe.cond);
pthread_join(thread_process, NULL);
perf_set_singlethreaded();
+ exit_process_thread(top);
return ret;
}
--
2.41.0.rc0.172.g3f132b7071-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-07 5:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 5:01 [PATCH v1 0/2] Fix leak sanitizer warnings in perf top Ian Rogers
2023-06-07 5:01 ` [PATCH v1 1/2] perf annotate: Fix parse_objdump_line memory leak Ian Rogers
2023-06-07 5:01 ` [PATCH v1 2/2] perf top: Add exit routine for main thread Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).