linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Namhyung Kim <namhyung@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>, Paul Mackerras <paulus@samba.org>,
	Namhyung Kim <namhyung.kim@lge.com>,
	LKML <linux-kernel@vger.kernel.org>, Jiri Olsa <jolsa@redhat.com>,
	David Ahern <dsahern@gmail.com>, Minchan Kim <minchan@kernel.org>
Subject: Re: [PATCH 01/13] perf script: Fix possible memory leaks
Date: Wed, 13 Aug 2014 09:21:31 +0300	[thread overview]
Message-ID: <53EB03EB.4040606@intel.com> (raw)
In-Reply-To: <1407825645-24586-2-git-send-email-namhyung@kernel.org>

On 08/12/2014 09:40 AM, Namhyung Kim wrote:
> Some paths in perf script don't call perf_session__delete() after
> creating a new session.
> 
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/builtin-script.c | 35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 868c17d09762..534172b889c3 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -1471,12 +1471,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
>  	bool show_full_info = false;
>  	bool header = false;
>  	bool header_only = false;
> +	bool script_started = false;
>  	char *rec_script_path = NULL;
>  	char *rep_script_path = NULL;
>  	struct perf_session *session;
>  	char *script_path = NULL;
>  	const char **__argv;
> -	int i, j, err;
> +	int i, j, err = 0;
>  	struct perf_script script = {
>  		.tool = {
>  			.sample		 = process_sample_event,
> @@ -1730,14 +1731,15 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
>  	if (header || header_only) {
>  		perf_session__fprintf_info(session, stdout, show_full_info);
>  		if (header_only)
> -			return 0;
> +			goto out_delete;
>  	}
>  
>  	script.session = session;
>  
>  	if (cpu_list) {
> -		if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
> -			return -1;
> +		err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
> +		if (err < 0)
> +			goto out_delete;
>  	}
>  
>  	if (!no_callchain)
> @@ -1752,53 +1754,60 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
>  		if (output_set_by_user()) {
>  			fprintf(stderr,
>  				"custom fields not supported for generated scripts");
> -			return -1;
> +			err = -EINVAL;
> +			goto out_delete;
>  		}
>  
>  		input = open(file.path, O_RDONLY);	/* input_name */
>  		if (input < 0) {
>  			perror("failed to open file");
> -			return -1;
> +			err = -errno;

Need to get errno before calling perror().

> +			goto out_delete;
>  		}
>  
>  		err = fstat(input, &perf_stat);
>  		if (err < 0) {
>  			perror("failed to stat file");
> -			return -1;
> +			goto out_delete;
>  		}
>  
>  		if (!perf_stat.st_size) {
>  			fprintf(stderr, "zero-sized file, nothing to do!\n");
> -			return 0;
> +			goto out_delete;
>  		}
>  
>  		scripting_ops = script_spec__lookup(generate_script_lang);
>  		if (!scripting_ops) {
>  			fprintf(stderr, "invalid language specifier");
> -			return -1;
> +			err = -ENOENT;
> +			goto out_delete;
>  		}
>  
>  		err = scripting_ops->generate_script(session->tevent.pevent,
>  						     "perf-script");
> -		goto out;
> +		goto out_delete;
>  	}
>  
>  	if (script_name) {
>  		err = scripting_ops->start_script(script_name, argc, argv);
>  		if (err)
> -			goto out;
> +			goto out_delete;
>  		pr_debug("perf script started with script %s\n\n", script_name);
> +		script_started = true;
>  	}
>  
>  
>  	err = perf_session__check_output_opt(session);
>  	if (err < 0)
> -		goto out;
> +		goto out_delete;
>  
>  	err = __cmd_script(&script);
>  
> +out_delete:

I added a flush method in a patch which acme has stashed in his
tmp.perf/core branch.  It would go here:

	if (script_started)
		flush_scripting();

>  	perf_session__delete(session);
> -	cleanup_scripting();
> +
> +	if (script_started)
> +		cleanup_scripting();
>  out:
>  	return err;
>  }
> 


  reply	other threads:[~2014-08-13  6:23 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12  6:40 [PATCHSET 00/13] perf tools: Fix vmlinux search path initialization Namhyung Kim
2014-08-12  6:40 ` [PATCH 01/13] perf script: Fix possible memory leaks Namhyung Kim
2014-08-13  6:21   ` Adrian Hunter [this message]
2014-08-13  7:05     ` Namhyung Kim
2014-08-13 19:27       ` Arnaldo Carvalho de Melo
2014-08-14  8:45   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 02/13] perf tools: Fix a memory leak in vmlinux_path__init() Namhyung Kim
2014-08-14  8:45   ` [tip:perf/core] perf symbols: " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 03/13] perf annotate: Move session handling out of __cmd_annotate() Namhyung Kim
2014-08-13 11:48   ` Jiri Olsa
2014-08-19  6:03     ` Namhyung Kim
2014-08-14  8:46   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 04/13] perf buildid-cache: Move session handling into cmd_buildid_cache() Namhyung Kim
2014-08-14  8:46   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 05/13] perf inject: Move session handling out of __cmd_inject() Namhyung Kim
2014-08-14  8:46   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 06/13] perf kmem: Move session handling out of __cmd_kmem() Namhyung Kim
2014-08-14  8:46   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 07/13] perf kvm: Move call to symbol__init() after creating session Namhyung Kim
2014-08-14  8:47   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 08/13] perf lock: " Namhyung Kim
2014-08-14  8:47   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 09/13] perf sched: " Namhyung Kim
2014-08-14  8:47   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 10/13] perf script: " Namhyung Kim
2014-08-14  8:47   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 11/13] perf timechart: " Namhyung Kim
2014-08-14  8:48   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 12/13] perf trace: " Namhyung Kim
2014-08-14  8:48   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-12  6:40 ` [PATCH 13/13] perf tools: Check recorded kernel version when finding vmlinux Namhyung Kim
2014-08-14  8:48   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-08-13 12:49 ` [PATCHSET 00/13] perf tools: Fix vmlinux search path initialization Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53EB03EB.4040606@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).