Skip to content

Commit

Permalink
perf tools: Fix resource leak of closedir() on the error paths
Browse files Browse the repository at this point in the history
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: e2091ce ("perf tools: Add MEM_TOPOLOGY feature to perf data file")
Fixes: cdb6b02 ("perf tools: Add pattern name checking to rm_rf")
Signed-off-by: Yunfeng Ye <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Alexey Budankov <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Feilong Lin <[email protected]>
Cc: Hu Shiyuan <[email protected]>
Cc: Igor Lubashev <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Martin KaFai Lau <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Yonghong Song <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
yeyunfeng-dev authored and acmel committed Oct 15, 2019
1 parent 98a8b2e commit 6080728
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,8 +1296,10 @@ static int build_mem_topology(struct memory_node *nodes, u64 size, u64 *cntp)
continue;

if (WARN_ONCE(cnt >= size,
"failed to write MEM_TOPOLOGY, way too many nodes\n"))
"failed to write MEM_TOPOLOGY, way too many nodes\n")) {
closedir(dir);
return -1;
}

ret = memory_node__read(&nodes[cnt++], idx);
}
Expand Down
6 changes: 4 additions & 2 deletions tools/perf/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ static int rm_rf_depth_pat(const char *path, int depth, const char **pat)
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;

if (!match_pat(d->d_name, pat))
return -2;
if (!match_pat(d->d_name, pat)) {
ret = -2;
break;
}

scnprintf(namebuf, sizeof(namebuf), "%s/%s",
path, d->d_name);
Expand Down

0 comments on commit 6080728

Please sign in to comment.