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>
This commit is contained in:
Thiago Macieira 2013-12-20 10:44:03 -08:00 committed by The Qt Project
parent eaedc04d90
commit bbcdfb324b

View File

@ -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