aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <[email protected]>2023-04-05 23:52:24 -0700
committerArnaldo Carvalho de Melo <[email protected]>2023-04-06 21:40:53 -0300
commit0ea8920e86e3232c56dc812c1f363fd20fce46c6 (patch)
tree4a09957433e13ba97fd7c2490d50f60de119b1c0
parent3d88aec0d42eec26b633fb2a473e294a1125bbd7 (diff)
perf pmu: Fix a few potential fd leaks
Ensure fd is closed on error paths. Signed-off-by: Ian Rogers <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Gaosheng Cui <[email protected]> Cc: German Gomez <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jing Zhang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Rob Herring <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Suzuki Poulouse <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/perf/util/pmu.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 96ef317bac41..9eedbfc9e863 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -494,9 +494,13 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head)
continue;
fd = openat(dirfd, name, O_RDONLY);
+ if (fd == -1) {
+ pr_debug("Cannot open %s\n", name);
+ continue;
+ }
file = fdopen(fd, "r");
if (!file) {
- pr_debug("Cannot open %s\n", name);
+ close(fd);
continue;
}
@@ -1882,9 +1886,13 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu)
continue;
fd = openat(caps_fd, name, O_RDONLY);
+ if (fd == -1)
+ continue;
file = fdopen(fd, "r");
- if (!file)
+ if (!file) {
+ close(fd);
continue;
+ }
if (!fgets(value, sizeof(value), file) ||
(perf_pmu__new_caps(&pmu->caps, name, value) < 0)) {