aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-08-15 16:06:47 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-08-15 17:10:59 -0400
commit60ebc159817fef86171616510b1228476d979556 (patch)
tree7db29266558d2e78bbc0c23a5c708c12af74dd0b
parent0325862dc364d8af524bf2db53ef4360ed55b989 (diff)
perf probe: Release resources on error when handling exit paths
Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Colin King <colin.king@canonical.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-zh2j4iqimralugke5qq7dn6d@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/probe-file.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index a8e76233c088..9c3b9ed5b3c3 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)
143 return NULL; 143 return NULL;
144 144
145 sl = strlist__new(NULL, NULL); 145 sl = strlist__new(NULL, NULL);
146 if (sl == NULL)
147 return NULL;
146 148
147 fddup = dup(fd); 149 fddup = dup(fd);
148 if (fddup < 0) 150 if (fddup < 0)
@@ -163,14 +165,16 @@ struct strlist *probe_file__get_rawlist(int fd)
163 ret = strlist__add(sl, buf); 165 ret = strlist__add(sl, buf);
164 if (ret < 0) { 166 if (ret < 0) {
165 pr_debug("strlist__add failed (%d)\n", ret); 167 pr_debug("strlist__add failed (%d)\n", ret);
166 strlist__delete(sl); 168 goto out_close_fp;
167 return NULL;
168 } 169 }
169 } 170 }
170 fclose(fp); 171 fclose(fp);
171 172
172 return sl; 173 return sl;
173 174
175out_close_fp:
176 fclose(fp);
177 goto out_free_sl;
174out_close_fddup: 178out_close_fddup:
175 close(fddup); 179 close(fddup);
176out_free_sl: 180out_free_sl:
@@ -467,8 +471,10 @@ static int probe_cache__load(struct probe_cache *pcache)
467 if (fddup < 0) 471 if (fddup < 0)
468 return -errno; 472 return -errno;
469 fp = fdopen(fddup, "r"); 473 fp = fdopen(fddup, "r");
470 if (!fp) 474 if (!fp) {
475 close(fddup);
471 return -EINVAL; 476 return -EINVAL;
477 }
472 478
473 while (!feof(fp)) { 479 while (!feof(fp)) {
474 if (!fgets(buf, MAX_CMDLEN, fp)) 480 if (!fgets(buf, MAX_CMDLEN, fp))