[libcamera-devel] libcamera: device_enumerator: Fix memory leak in error path

Message ID 20190108144621.10546-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 824ed85553cf65ba879b03e326c8647619d7ede1
Headers show
Series
  • [libcamera-devel] libcamera: device_enumerator: Fix memory leak in error path
Related show

Commit Message

Laurent Pinchart Jan. 8, 2019, 2:46 p.m. UTC
The DeviceEnumerator::create() function allocates a
DeviceEnumeratorUdev and fails to delete it in the error path, causing a
memory leak. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/device_enumerator.cpp | 2 ++
 1 file changed, 2 insertions(+)

Comments

Niklas Söderlund Jan. 9, 2019, 3:40 p.m. UTC | #1
Hi Laurent,

Thanks for fixing my mistake :-)

On 2019-01-08 16:46:21 +0200, Laurent Pinchart wrote:
> The DeviceEnumerator::create() function allocates a
> DeviceEnumeratorUdev and fails to delete it in the error path, causing a
> memory leak. Fix it.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/device_enumerator.cpp | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
> index f1d016db64a0..0d18e75525af 100644
> --- a/src/libcamera/device_enumerator.cpp
> +++ b/src/libcamera/device_enumerator.cpp
> @@ -140,6 +140,8 @@ DeviceEnumerator *DeviceEnumerator::create()
>  	if (!enumerator->init())
>  		return enumerator;
>  
> +	delete enumerator;
> +
>  	/*
>  	 * Either udev is not available or udev initialization failed. Fall back
>  	 * on the sysfs enumerator.
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
index f1d016db64a0..0d18e75525af 100644
--- a/src/libcamera/device_enumerator.cpp
+++ b/src/libcamera/device_enumerator.cpp
@@ -140,6 +140,8 @@  DeviceEnumerator *DeviceEnumerator::create()
 	if (!enumerator->init())
 		return enumerator;
 
+	delete enumerator;
+
 	/*
 	 * Either udev is not available or udev initialization failed. Fall back
 	 * on the sysfs enumerator.