Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1733030

Re: [PATCH] tools: perf: fix leaking rec_argv in error cases

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH] tools: perf: fix leaking rec_argv in error cases
Date 2017-09-15 21:10 +0200
Message-ID <uq49X-7ct-1@gated-at.bofh.it> (permalink)
References <uplmx-2Zr-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Em Wed, Sep 13, 2017 at 09:14:19PM +0200, Martin Kepplinger escreveu:
> Let's free the allocated rec_argv in case we return early, in
> order to avoid leaking memory.
> 
> This adds free() at a few very similar places across the tree
> where it was missing.

Thanks, applied.

- Arnaldo
 
> Signed-off-by: Martin Kepplinger <martink@posteo.de>
> ---
>  tools/perf/builtin-c2c.c       | 1 +
>  tools/perf/builtin-mem.c       | 1 +
>  tools/perf/builtin-timechart.c | 4 +++-
>  tools/perf/builtin-trace.c     | 1 +
>  4 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
> index 475999e48f66..bb1ee22bd221 100644
> --- a/tools/perf/builtin-c2c.c
> +++ b/tools/perf/builtin-c2c.c
> @@ -2732,6 +2732,7 @@ static int perf_c2c__record(int argc, const char **argv)
>  		if (!perf_mem_events[j].supported) {
>  			pr_err("failed: event '%s' not supported\n",
>  			       perf_mem_events[j].name);
> +			free(rec_argv);
>  			return -1;
>  		}
>  
> diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
> index 0f15634ef82c..6940490bc3f9 100644
> --- a/tools/perf/builtin-mem.c
> +++ b/tools/perf/builtin-mem.c
> @@ -112,6 +112,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
>  		if (!perf_mem_events[j].supported) {
>  			pr_err("failed: event '%s' not supported\n",
>  			       perf_mem_events__name(j));
> +			free(rec_argv);
>  			return -1;
>  		}
>  
> diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
> index 4e2e61695986..01de01ca14f2 100644
> --- a/tools/perf/builtin-timechart.c
> +++ b/tools/perf/builtin-timechart.c
> @@ -1732,8 +1732,10 @@ static int timechart__io_record(int argc, const char **argv)
>  	if (rec_argv == NULL)
>  		return -ENOMEM;
>  
> -	if (asprintf(&filter, "common_pid != %d", getpid()) < 0)
> +	if (asprintf(&filter, "common_pid != %d", getpid()) < 0) {
> +		free(rec_argv);
>  		return -ENOMEM;
> +	}
>  
>  	p = rec_argv;
>  	for (i = 0; i < common_args_nr; i++)
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index 771ddab94bb0..dd8eec4c755c 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -2078,6 +2078,7 @@ static int trace__record(struct trace *trace, int argc, const char **argv)
>  			rec_argv[j++] = "syscalls:sys_enter,syscalls:sys_exit";
>  		else {
>  			pr_err("Neither raw_syscalls nor syscalls events exist.\n");
> +			free(rec_argv);
>  			return -1;
>  		}
>  	}
> -- 
> 2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] tools: perf: fix leaking rec_argv in error cases Martin Kepplinger <martink@posteo.de> - 2017-09-13 21:20 +0200
  Re: [PATCH] tools: perf: fix leaking rec_argv in error cases Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-09-15 21:10 +0200
  [tip:perf/core] perf tools: Fix leaking rec_argv in error cases tip-bot for Martin Kepplinger <tipbot@zytor.com> - 2017-09-22 18:50 +0200

csiph-web