summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-12-20 10:44:03 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-10 02:33:32 +0100
commitbbcdfb324b473373d37c005e2e005f0870cc74ce (patch)
tree4e09889a64936ac0037047145dd723989906dab0 /src/testlib
parenteaedc04d90fdfc28cc9de96a32635bf327769086 (diff)
Fix file descriptor leak in the perf event counter
We opened the counter at every start(), even if we had already started before. Some of the benchlib's options caused it to start() and stop() over and over again, like -minimumvalue and -minimumtotal, which could leak to fd exhaustion (EMFILE). Change-Id: Ifeb7cca65c758877be600dc22928bea74f499934 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qbenchmarkperfevents.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp
index acc11b09ac..30a0d3ea9c 100644
--- a/src/testlib/qbenchmarkperfevents.cpp
+++ b/src/testlib/qbenchmarkperfevents.cpp
@@ -515,16 +515,18 @@ void QBenchmarkPerfEventsMeasurer::start()
{
initPerf();
- // pid == 0 -> attach to the current process
- // cpu == -1 -> monitor on all CPUs
- // group_fd == -1 -> this is the group leader
- // flags == 0 -> reserved, must be zero
- fd = perf_event_open(&attr, 0, -1, -1, 0);
if (fd == -1) {
- perror("QBenchmarkPerfEventsMeasurer::start: perf_event_open");
- exit(1);
- } else {
- ::fcntl(fd, F_SETFD, FD_CLOEXEC);
+ // pid == 0 -> attach to the current process
+ // cpu == -1 -> monitor on all CPUs
+ // group_fd == -1 -> this is the group leader
+ // flags == 0 -> reserved, must be zero
+ fd = perf_event_open(&attr, 0, -1, -1, 0);
+ if (fd == -1) {
+ perror("QBenchmarkPerfEventsMeasurer::start: perf_event_open");
+ exit(1);
+ } else {
+ ::fcntl(fd, F_SETFD, FD_CLOEXEC);
+ }
}
// enable the counter