Skip to content

Commit

Permalink
perf probe: Release resources on error when handling exit paths
Browse files Browse the repository at this point in the history
Cc: Adrian Hunter <[email protected]>
Cc: Colin King <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Aug 15, 2016
1 parent 0325862 commit 60ebc15
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tools/perf/util/probe-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 60ebc15

Please sign in to comment.