perf script: Fix possible memory leaks
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>
This commit is contained in:

committed by
Arnaldo Carvalho de Melo

parent
f6edb53c49
commit
6cc870f09d
@@ -1471,12 +1471,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
|
|||||||
bool show_full_info = false;
|
bool show_full_info = false;
|
||||||
bool header = false;
|
bool header = false;
|
||||||
bool header_only = false;
|
bool header_only = false;
|
||||||
|
bool script_started = false;
|
||||||
char *rec_script_path = NULL;
|
char *rec_script_path = NULL;
|
||||||
char *rep_script_path = NULL;
|
char *rep_script_path = NULL;
|
||||||
struct perf_session *session;
|
struct perf_session *session;
|
||||||
char *script_path = NULL;
|
char *script_path = NULL;
|
||||||
const char **__argv;
|
const char **__argv;
|
||||||
int i, j, err;
|
int i, j, err = 0;
|
||||||
struct perf_script script = {
|
struct perf_script script = {
|
||||||
.tool = {
|
.tool = {
|
||||||
.sample = process_sample_event,
|
.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) {
|
if (header || header_only) {
|
||||||
perf_session__fprintf_info(session, stdout, show_full_info);
|
perf_session__fprintf_info(session, stdout, show_full_info);
|
||||||
if (header_only)
|
if (header_only)
|
||||||
return 0;
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
script.session = session;
|
script.session = session;
|
||||||
|
|
||||||
if (cpu_list) {
|
if (cpu_list) {
|
||||||
if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
|
err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
|
||||||
return -1;
|
if (err < 0)
|
||||||
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!no_callchain)
|
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()) {
|
if (output_set_by_user()) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"custom fields not supported for generated scripts");
|
"custom fields not supported for generated scripts");
|
||||||
return -1;
|
err = -EINVAL;
|
||||||
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
input = open(file.path, O_RDONLY); /* input_name */
|
input = open(file.path, O_RDONLY); /* input_name */
|
||||||
if (input < 0) {
|
if (input < 0) {
|
||||||
|
err = -errno;
|
||||||
perror("failed to open file");
|
perror("failed to open file");
|
||||||
return -1;
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = fstat(input, &perf_stat);
|
err = fstat(input, &perf_stat);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
perror("failed to stat file");
|
perror("failed to stat file");
|
||||||
return -1;
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!perf_stat.st_size) {
|
if (!perf_stat.st_size) {
|
||||||
fprintf(stderr, "zero-sized file, nothing to do!\n");
|
fprintf(stderr, "zero-sized file, nothing to do!\n");
|
||||||
return 0;
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
scripting_ops = script_spec__lookup(generate_script_lang);
|
scripting_ops = script_spec__lookup(generate_script_lang);
|
||||||
if (!scripting_ops) {
|
if (!scripting_ops) {
|
||||||
fprintf(stderr, "invalid language specifier");
|
fprintf(stderr, "invalid language specifier");
|
||||||
return -1;
|
err = -ENOENT;
|
||||||
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scripting_ops->generate_script(session->tevent.pevent,
|
err = scripting_ops->generate_script(session->tevent.pevent,
|
||||||
"perf-script");
|
"perf-script");
|
||||||
goto out;
|
goto out_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (script_name) {
|
if (script_name) {
|
||||||
err = scripting_ops->start_script(script_name, argc, argv);
|
err = scripting_ops->start_script(script_name, argc, argv);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out_delete;
|
||||||
pr_debug("perf script started with script %s\n\n", script_name);
|
pr_debug("perf script started with script %s\n\n", script_name);
|
||||||
|
script_started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
err = perf_session__check_output_opt(session);
|
err = perf_session__check_output_opt(session);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto out;
|
goto out_delete;
|
||||||
|
|
||||||
err = __cmd_script(&script);
|
err = __cmd_script(&script);
|
||||||
|
|
||||||
|
out_delete:
|
||||||
perf_session__delete(session);
|
perf_session__delete(session);
|
||||||
cleanup_scripting();
|
|
||||||
|
if (script_started)
|
||||||
|
cleanup_scripting();
|
||||||
out:
|
out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user