summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYunfeng Ye <yeyunfeng@huawei.com>2019-10-15 04:30:08 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-10-15 10:54:11 -0400
commit6080728ff8e9c9116e52e6f840152356ac2fea56 (patch)
tree58aee842faae6efa54077e2545e0fda4b52290c6
parent98a8b2e60c69927b1f405c3b001a1de3f4e53901 (diff)
perf tools: Fix resource leak of closedir() on the error paths
Both build_mem_topology() and rm_rf_depth_pat() have resource leaks of closedir() on the error paths. Fix this by calling closedir() before function returns. Fixes: e2091cedd51b ("perf tools: Add MEM_TOPOLOGY feature to perf data file") Fixes: cdb6b0235f17 ("perf tools: Add pattern name checking to rm_rf") Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Feilong Lin <linfeilong@huawei.com> Cc: Hu Shiyuan <hushiyuan@huawei.com> Cc: Igor Lubashev <ilubashe@akamai.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Martin KaFai Lau <kafai@fb.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@fb.com> Cc: Yonghong Song <yhs@fb.com> Link: http://lore.kernel.org/lkml/cd5f7cd2-b80d-6add-20a1-32f4f43e0744@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/header.c4
-rw-r--r--tools/perf/util/util.c6
2 files changed, 7 insertions, 3 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 86d9396cb131..becc2d109423 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1296,8 +1296,10 @@ static int build_mem_topology(struct memory_node *nodes, u64 size, u64 *cntp)
1296 continue; 1296 continue;
1297 1297
1298 if (WARN_ONCE(cnt >= size, 1298 if (WARN_ONCE(cnt >= size,
1299 "failed to write MEM_TOPOLOGY, way too many nodes\n")) 1299 "failed to write MEM_TOPOLOGY, way too many nodes\n")) {
1300 closedir(dir);
1300 return -1; 1301 return -1;
1302 }
1301 1303
1302 ret = memory_node__read(&nodes[cnt++], idx); 1304 ret = memory_node__read(&nodes[cnt++], idx);
1303 } 1305 }
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 5eda6e19c947..ae56c766eda1 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -154,8 +154,10 @@ static int rm_rf_depth_pat(const char *path, int depth, const char **pat)
154 if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) 154 if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
155 continue; 155 continue;
156 156
157 if (!match_pat(d->d_name, pat)) 157 if (!match_pat(d->d_name, pat)) {
158 return -2; 158 ret = -2;
159 break;
160 }
159 161
160 scnprintf(namebuf, sizeof(namebuf), "%s/%s", 162 scnprintf(namebuf, sizeof(namebuf), "%s/%s",
161 path, d->d_name); 163 path, d->d_name);