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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0325862d
...@@ -143,6 +143,8 @@ struct strlist *probe_file__get_rawlist(int fd) ...@@ -143,6 +143,8 @@ struct strlist *probe_file__get_rawlist(int fd)
return NULL; return NULL;
sl = strlist__new(NULL, NULL); sl = strlist__new(NULL, NULL);
if (sl == NULL)
return NULL;
fddup = dup(fd); fddup = dup(fd);
if (fddup < 0) if (fddup < 0)
...@@ -163,14 +165,16 @@ struct strlist *probe_file__get_rawlist(int fd) ...@@ -163,14 +165,16 @@ struct strlist *probe_file__get_rawlist(int fd)
ret = strlist__add(sl, buf); ret = strlist__add(sl, buf);
if (ret < 0) { if (ret < 0) {
pr_debug("strlist__add failed (%d)\n", ret); pr_debug("strlist__add failed (%d)\n", ret);
strlist__delete(sl); goto out_close_fp;
return NULL;
} }
} }
fclose(fp); fclose(fp);
return sl; return sl;
out_close_fp:
fclose(fp);
goto out_free_sl;
out_close_fddup: out_close_fddup:
close(fddup); close(fddup);
out_free_sl: out_free_sl:
...@@ -467,8 +471,10 @@ static int probe_cache__load(struct probe_cache *pcache) ...@@ -467,8 +471,10 @@ static int probe_cache__load(struct probe_cache *pcache)
if (fddup < 0) if (fddup < 0)
return -errno; return -errno;
fp = fdopen(fddup, "r"); fp = fdopen(fddup, "r");
if (!fp) if (!fp) {
close(fddup);
return -EINVAL; return -EINVAL;
}
while (!feof(fp)) { while (!feof(fp)) {
if (!fgets(buf, MAX_CMDLEN, fp)) if (!fgets(buf, MAX_CMDLEN, fp))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment