* [PATCH v2] tools/perf/util: Fix memory leak in trace-event-info.c
@ 2013-10-11 1:21 Felipe Pena
2013-10-14 5:07 ` Namhyung Kim
0 siblings, 1 reply; 2+ messages in thread
From: Felipe Pena @ 2013-10-11 1:21 UTC (permalink / raw)
To: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Borislav Petkov
Cc: linux-kernel, Felipe Pena
Fix for a memory leak on tracing_data_get() function when returning NULL explicitly
Signed-off-by: Felipe Pena <felipensp@gmail.com>
---
tools/perf/util/trace-event-info.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index f3c9e55..2a0c3c9 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -518,13 +518,15 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
"/tmp/perf-XXXXXX");
if (!mkstemp(tdata->temp_file)) {
pr_debug("Can't make temp file");
- return NULL;
+ err = -1;
+ goto err_tdata;
}
temp_fd = open(tdata->temp_file, O_RDWR);
if (temp_fd < 0) {
pr_debug("Can't read '%s'", tdata->temp_file);
- return NULL;
+ err = -1;
+ goto err_tdata;
}
/*
@@ -562,6 +564,7 @@ out:
output_fd = fd;
}
+err_tdata:
if (err) {
free(tdata);
tdata = NULL;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] tools/perf/util: Fix memory leak in trace-event-info.c
2013-10-11 1:21 [PATCH v2] tools/perf/util: Fix memory leak in trace-event-info.c Felipe Pena
@ 2013-10-14 5:07 ` Namhyung Kim
0 siblings, 0 replies; 2+ messages in thread
From: Namhyung Kim @ 2013-10-14 5:07 UTC (permalink / raw)
To: Felipe Pena
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Arnaldo Carvalho de Melo, Borislav Petkov, linux-kernel
Hi Felipe,
On Thu, 10 Oct 2013 22:21:29 -0300, Felipe Pena wrote:
> Fix for a memory leak on tracing_data_get() function when returning NULL explicitly
>
> Signed-off-by: Felipe Pena <felipensp@gmail.com>
> ---
> tools/perf/util/trace-event-info.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
> index f3c9e55..2a0c3c9 100644
> --- a/tools/perf/util/trace-event-info.c
> +++ b/tools/perf/util/trace-event-info.c
> @@ -518,13 +518,15 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
> "/tmp/perf-XXXXXX");
> if (!mkstemp(tdata->temp_file)) {
> pr_debug("Can't make temp file");
> - return NULL;
> + err = -1;
> + goto err_tdata;
> }
>
> temp_fd = open(tdata->temp_file, O_RDWR);
> if (temp_fd < 0) {
> pr_debug("Can't read '%s'", tdata->temp_file);
> - return NULL;
> + err = -1;
> + goto err_tdata;
I'd rather initialize err to -1 at the beginning. And the malloc of
tdata should also be handled like this.
Thanks,
Namhyung
> }
>
> /*
> @@ -562,6 +564,7 @@ out:
> output_fd = fd;
> }
>
> +err_tdata:
> if (err) {
> free(tdata);
> tdata = NULL;
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-10-14 5:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-11 1:21 [PATCH v2] tools/perf/util: Fix memory leak in trace-event-info.c Felipe Pena
2013-10-14 5:07 ` Namhyung Kim
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.