[libcamera-devel,v2,1/3] libcamera: timer: Stop timer when it is deleted

Message ID 20190630162514.20522-2-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: ipc: unix: Add a IPC mechanism based on Unix sockets
Related show

Commit Message

Niklas Söderlund June 30, 2019, 4:25 p.m. UTC
If a timer is running while it's deleted it is still register with the
event dispatcher. This causes a segmentation fault when the timer
time-out and its signal is emitted. Fix this my stopping the timer when
it's deleted.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 include/libcamera/timer.h | 1 +
 src/libcamera/timer.cpp   | 5 +++++
 2 files changed, 6 insertions(+)

Comments

Laurent Pinchart June 30, 2019, 11:41 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Sun, Jun 30, 2019 at 06:25:12PM +0200, Niklas Söderlund wrote:
> If a timer is running while it's deleted it is still register with the
> event dispatcher. This causes a segmentation fault when the timer
> time-out and its signal is emitted. Fix this my stopping the timer when
> it's deleted.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Good catch.

Conditioned by another patch that extends the Timer tests to catch this,

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

> ---
>  include/libcamera/timer.h | 1 +
>  src/libcamera/timer.cpp   | 5 +++++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h
> index 97dcc01f493dc70d..f082339b1fed9de7 100644
> --- a/include/libcamera/timer.h
> +++ b/include/libcamera/timer.h
> @@ -17,6 +17,7 @@ class Timer
>  {
>  public:
>  	Timer();
> +	~Timer();
>  
>  	void start(unsigned int msec);
>  	void stop();
> diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp
> index 1cce45085c61be2f..0dcb4e767be30b32 100644
> --- a/src/libcamera/timer.cpp
> +++ b/src/libcamera/timer.cpp
> @@ -43,6 +43,11 @@ Timer::Timer()
>  {
>  }
>  
> +Timer::~Timer()
> +{
> +	stop();
> +}
> +
>  /**
>   * \brief Start or restart the timer with a timeout of \a msec
>   * \param[in] msec The timer duration in milliseconds

Patch

diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h
index 97dcc01f493dc70d..f082339b1fed9de7 100644
--- a/include/libcamera/timer.h
+++ b/include/libcamera/timer.h
@@ -17,6 +17,7 @@  class Timer
 {
 public:
 	Timer();
+	~Timer();
 
 	void start(unsigned int msec);
 	void stop();
diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp
index 1cce45085c61be2f..0dcb4e767be30b32 100644
--- a/src/libcamera/timer.cpp
+++ b/src/libcamera/timer.cpp
@@ -43,6 +43,11 @@  Timer::Timer()
 {
 }
 
+Timer::~Timer()
+{
+	stop();
+}
+
 /**
  * \brief Start or restart the timer with a timeout of \a msec
  * \param[in] msec The timer duration in milliseconds