From 8ad48d67742ca1ea2c5f10a29f47684e959199da Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Mon, 13 Jul 2015 21:25:48 +0200 Subject: [PATCH] Protect against emitting inactivityDetected() while it'is still processed. --- src/core/InactivityTimer.cpp | 7 +++++++ src/core/InactivityTimer.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/core/InactivityTimer.cpp b/src/core/InactivityTimer.cpp index 762c8720..dd162e69 100644 --- a/src/core/InactivityTimer.cpp +++ b/src/core/InactivityTimer.cpp @@ -67,7 +67,14 @@ bool InactivityTimer::eventFilter(QObject* watched, QEvent* event) void InactivityTimer::timeout() { + // make sure we don't emit the signal a second time while it's still processed + if (!m_emitMutx.tryLock()) { + return; + } + if (m_active && !m_timer->isActive()) { Q_EMIT inactivityDetected(); } + + m_emitMutx.unlock(); } diff --git a/src/core/InactivityTimer.h b/src/core/InactivityTimer.h index 14e4852b..e0a21e08 100644 --- a/src/core/InactivityTimer.h +++ b/src/core/InactivityTimer.h @@ -18,6 +18,7 @@ #ifndef KEEPASSX_INACTIVITYTIMER_H #define KEEPASSX_INACTIVITYTIMER_H +#include #include #include "core/Global.h" @@ -46,6 +47,7 @@ private Q_SLOTS: private: QTimer* m_timer; bool m_active; + QMutex m_emitMutx; }; #endif // KEEPASSX_INACTIVITYTIMER_H