From 61e076a2957ee73a05f0f78585c2dfd17ee2fa4b Mon Sep 17 00:00:00 2001 From: Jens-H Date: Sat, 28 Nov 2020 19:01:25 +0100 Subject: [PATCH] Fix LinuxEvents destructor to close all fd --- benchmarks/linux-perf-events.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/benchmarks/linux-perf-events.h b/benchmarks/linux-perf-events.h index 2725205..46d9db9 100644 --- a/benchmarks/linux-perf-events.h +++ b/benchmarks/linux-perf-events.h @@ -53,7 +53,11 @@ template class LinuxEvents { temp_result_vec.resize(num_events * 2 + 1); } - ~LinuxEvents() { close(fd); } + ~LinuxEvents() { + // This solution expects that the fds are increasing numbers without + // gaps. Certainly this is not always true. + for (int i = fd; fd - num_events - i != 0; i--) { close(i); } + } inline void start() { if (ioctl(fd, PERF_EVENT_IOC_RESET, PERF_IOC_FLAG_GROUP) == -1) {