[libcamera-devel] libcamera: device_enumerator_udev: Initialize monitor_ and notifier_ to nullptr

Message ID 20200802231652.360645-1-niklas.soderlund@ragnatech.se
State Superseded
Commit 108b6a8a15487b982612f34bd7b00e7b05be864a
Headers show
Series
  • [libcamera-devel] libcamera: device_enumerator_udev: Initialize monitor_ and notifier_ to nullptr
Related show

Commit Message

Niklas Söderlund Aug. 2, 2020, 11:16 p.m. UTC
The monitor_ and notifier_ pointers are acted on in the destructor if
not set to nullptr, the pointers are however first initialized in
enumerate(). If the object is deleted without enumerate() being called
the destructor acts on uninitialized pointers, fix this by initializing
them to nullptr.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/device_enumerator_udev.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Laurent Pinchart Aug. 2, 2020, 11:31 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Mon, Aug 03, 2020 at 01:16:52AM +0200, Niklas Söderlund wrote:
> The monitor_ and notifier_ pointers are acted on in the destructor if
> not set to nullptr, the pointers are however first initialized in
> enumerate(). If the object is deleted without enumerate() being called
> the destructor acts on uninitialized pointers, fix this by initializing
> them to nullptr.

Note that monitor_ is created in init(), not enumerate(). The issue is
still the same though, only the commit message should be updated.

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

> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/libcamera/device_enumerator_udev.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
> index 56ca4dc2804b46b9..96689daa5dd113dc 100644
> --- a/src/libcamera/device_enumerator_udev.cpp
> +++ b/src/libcamera/device_enumerator_udev.cpp
> @@ -27,7 +27,7 @@ namespace libcamera {
>  LOG_DECLARE_CATEGORY(DeviceEnumerator)
>  
>  DeviceEnumeratorUdev::DeviceEnumeratorUdev()
> -	: udev_(nullptr)
> +	: udev_(nullptr), monitor_(nullptr), notifier_(nullptr)
>  {
>  }
>
Umang Jain Aug. 3, 2020, 5:38 a.m. UTC | #2
Hi Niklas, Laurent,

On 8/3/20 5:01 AM, Laurent Pinchart wrote:
> Hi Niklas,
>
> Thank you for the patch.
>
> On Mon, Aug 03, 2020 at 01:16:52AM +0200, Niklas Söderlund wrote:
>> The monitor_ and notifier_ pointers are acted on in the destructor if
>> not set to nullptr, the pointers are however first initialized in
>> enumerate(). If the object is deleted without enumerate() being called
>> the destructor acts on uninitialized pointers, fix this by initializing
>> them to nullptr.
> Note that monitor_ is created in init(), not enumerate(). The issue is
> still the same though, only the commit message should be updated.
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Ditto. The commit message is the only change needed.
Reviewed-by: Umang Jain <email@uajain.com>
>
>> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
>> ---
>>   src/libcamera/device_enumerator_udev.cpp | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
>> index 56ca4dc2804b46b9..96689daa5dd113dc 100644
>> --- a/src/libcamera/device_enumerator_udev.cpp
>> +++ b/src/libcamera/device_enumerator_udev.cpp
>> @@ -27,7 +27,7 @@ namespace libcamera {
>>   LOG_DECLARE_CATEGORY(DeviceEnumerator)
>>   
>>   DeviceEnumeratorUdev::DeviceEnumeratorUdev()
>> -	: udev_(nullptr)
>> +	: udev_(nullptr), monitor_(nullptr), notifier_(nullptr)
>>   {
>>   }
>>

Patch

diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
index 56ca4dc2804b46b9..96689daa5dd113dc 100644
--- a/src/libcamera/device_enumerator_udev.cpp
+++ b/src/libcamera/device_enumerator_udev.cpp
@@ -27,7 +27,7 @@  namespace libcamera {
 LOG_DECLARE_CATEGORY(DeviceEnumerator)
 
 DeviceEnumeratorUdev::DeviceEnumeratorUdev()
-	: udev_(nullptr)
+	: udev_(nullptr), monitor_(nullptr), notifier_(nullptr)
 {
 }