From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
Minchan Kim <minchan@kernel.org>,
Namhyung Kim <namhyung.kim@lge.com>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 14/41] perf script: Fix possible memory leaks
Date: Wed, 13 Aug 2014 19:48:00 -0300 [thread overview]
Message-ID: <1407970107-24540-15-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1407970107-24540-1-git-send-email-acme@kernel.org>
From: Namhyung Kim <namhyung@kernel.org>
Some paths in perf script don't call perf_session__delete() after
creating a new session.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1407825645-24586-2-git-send-email-namhyung@kernel.org
[ Saved errno value before calling perror(), as pointed out by Adrian Hunter ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
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..c84d723e0484 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) {
+ err = -errno;
perror("failed to open file");
- return -1;
+ 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:
perf_session__delete(session);
- cleanup_scripting();
+
+ if (script_started)
+ cleanup_scripting();
out:
return err;
}
--
1.9.3
next prev parent reply other threads:[~2014-08-13 22:49 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-13 22:47 [GIT PULL 00/41] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 01/41] perf top: Don't look for kernel idle symbols in all DSOs Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 02/41] perf tools: Add cpu_startup_entry to the list of kernel idle symbols Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 03/41] perf top: Join the display thread on exit Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 04/41] perf tools: Introduce set_term_quiet_input helper function Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 05/41] perf top: Setup signals for terminal output Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 06/41] perf kvm: Fix stdin handling for 'kvm stat live' command Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 07/41] perf probe: Fix --list option to show events only with uprobe events Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 08/41] perf probe: Fix --del option to delete " Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 09/41] perf trace: Add beautifier for mremap flags param Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 10/41] perf tools: Fix CLOEXEC probe for perf_event_paranoid == 2 Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 11/41] perf tools: Fix one of the probe events to exclude kernel Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 12/41] perf tools: Fix probing the kernel API with cpu-wide events Arnaldo Carvalho de Melo
2014-08-13 22:47 ` [PATCH 13/41] perf tools: Prefer to use a cpu-wide event for probing CLOEXEC Arnaldo Carvalho de Melo
2014-08-13 22:48 ` Arnaldo Carvalho de Melo [this message]
2014-08-13 22:48 ` [PATCH 15/41] perf symbols: Fix a memory leak in vmlinux_path__init() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 16/41] perf annotate: Move session handling out of __cmd_annotate() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 17/41] perf buildid-cache: Move session handling into cmd_buildid_cache() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 18/41] perf inject: Move session handling out of __cmd_inject() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 19/41] perf kmem: Move session handling out of __cmd_kmem() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 20/41] perf kvm: Move call to symbol__init() after creating session Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 21/41] perf lock: " Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 22/41] perf sched: " Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 23/41] perf script: " Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 24/41] perf timechart: " Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 25/41] perf trace: " Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 26/41] perf tools: Check recorded kernel version when finding vmlinux Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 27/41] perf hists browser: Fix a small callchain display bug Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 28/41] perf report: Set proper sort__mode for the branch option Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 29/41] perf top: Fix -z option behavior Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 30/41] perf top: Handle 'z' key for toggle zeroing samples in TUI Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 31/41] perf symbols: Don't demangle parameters and such by default Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 32/41] perf symbols: Fix missing label symbols Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 33/41] perf evlist: Add 'system_wide' option Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 34/41] perf evlist: Add perf_evlist__set_tracking_event() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 35/41] perf session: Add perf_session__peek_event() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 36/41] perf script: Allow callchains if any event samples them Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 37/41] perf script python: Add helpers for calling Python objects Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 38/41] perf tools: Identify which comms are from exec Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 39/41] perf machine: Add machine__thread_exec_comm() Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 40/41] perf tools: Add flags and insn_len to struct sample Arnaldo Carvalho de Melo
2014-08-13 22:48 ` [PATCH 41/41] perf evlist: Add perf_evlist__enable_event_idx() Arnaldo Carvalho de Melo
2014-08-14 8:40 ` [GIT PULL 00/41] perf/core improvements and fixes Ingo Molnar
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=1407970107-24540-15-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--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