[libcamera-devel,1/2] qcam: Fix unregister of not registered timer

Message ID 20190927023023.722396-2-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • qcam: Fix issues in the Qt event dispatcher
Related show

Commit Message

Niklas Söderlund Sept. 27, 2019, 2:30 a.m. UTC
If a unregistered timer is given to QtEventDispatcher::unregisterTimer()
an error is printed and Qt gets confused and locks up. Fix this by
following the libcamera documentation that passing a unregistered timer
is a no-op.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/qcam/qt_event_dispatcher.cpp | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Laurent Pinchart Sept. 27, 2019, 12:13 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Fri, Sep 27, 2019 at 04:30:22AM +0200, Niklas Söderlund wrote:
> If a unregistered timer is given to QtEventDispatcher::unregisterTimer()

s/If a/If an/

> an error is printed and Qt gets confused and locks up. Fix this by
> following the libcamera documentation that passing a unregistered timer
> is a no-op.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/qcam/qt_event_dispatcher.cpp | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/qcam/qt_event_dispatcher.cpp b/src/qcam/qt_event_dispatcher.cpp
> index 5ba451bf88cef6e8..6b332f6265d01fe0 100644
> --- a/src/qcam/qt_event_dispatcher.cpp
> +++ b/src/qcam/qt_event_dispatcher.cpp
> @@ -120,6 +120,10 @@ void QtEventDispatcher::registerTimer(Timer *timer)
>  void QtEventDispatcher::unregisterTimer(Timer *timer)
>  {
>  	auto it = timerIds_.find(timer);
> +

Nitpicking, I'd remove this blank line.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +	if (it == timerIds_.end())
> +		return;
> +
>  	timers_.erase(it->second);
>  	killTimer(it->second);
>  	timerIds_.erase(it);

Patch

diff --git a/src/qcam/qt_event_dispatcher.cpp b/src/qcam/qt_event_dispatcher.cpp
index 5ba451bf88cef6e8..6b332f6265d01fe0 100644
--- a/src/qcam/qt_event_dispatcher.cpp
+++ b/src/qcam/qt_event_dispatcher.cpp
@@ -120,6 +120,10 @@  void QtEventDispatcher::registerTimer(Timer *timer)
 void QtEventDispatcher::unregisterTimer(Timer *timer)
 {
 	auto it = timerIds_.find(timer);
+
+	if (it == timerIds_.end())
+		return;
+
 	timers_.erase(it->second);
 	killTimer(it->second);
 	timerIds_.erase(it);