[tip:perf/urgent] perf probe: Release resources on error when handling exit paths
From: tip-bot for Arnaldo Carvalho de Melo
Date: Tue Aug 16 2016 - 14:17:11 EST
Commit-ID: 60ebc159817fef86171616510b1228476d979556
Gitweb: http://git.kernel.org/tip/60ebc159817fef86171616510b1228476d979556
Author: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
AuthorDate: Mon, 15 Aug 2016 17:06:47 -0300
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Mon, 15 Aug 2016 18:10:59 -0300
perf probe: Release resources on error when handling exit paths
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Colin King <colin.king@xxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-zh2j4iqimralugke5qq7dn6d@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/probe-file.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index a8e7623..9c3b9ed 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -143,6 +143,8 @@ struct strlist *probe_file__get_rawlist(int fd)
return NULL;
sl = strlist__new(NULL, NULL);
+ if (sl == NULL)
+ return NULL;
fddup = dup(fd);
if (fddup < 0)
@@ -163,14 +165,16 @@ struct strlist *probe_file__get_rawlist(int fd)
ret = strlist__add(sl, buf);
if (ret < 0) {
pr_debug("strlist__add failed (%d)\n", ret);
- strlist__delete(sl);
- return NULL;
+ goto out_close_fp;
}
}
fclose(fp);
return sl;
+out_close_fp:
+ fclose(fp);
+ goto out_free_sl;
out_close_fddup:
close(fddup);
out_free_sl:
@@ -467,8 +471,10 @@ static int probe_cache__load(struct probe_cache *pcache)
if (fddup < 0)
return -errno;
fp = fdopen(fddup, "r");
- if (!fp)
+ if (!fp) {
+ close(fddup);
return -EINVAL;
+ }
while (!feof(fp)) {
if (!fgets(buf, MAX_CMDLEN, fp))