[libcamera-devel,03/14] libcamera: bound_method: Fix memory leak with direct connections

Message ID 20200104050947.7673-4-laurent.pinchart@ideasonboard.com
State Accepted
Commit 451ffd1fcd4e1287c3a600e83e61028aab74be59
Headers show
Series
  • object: Propagate return value of invoked method
Related show

Commit Message

Laurent Pinchart Jan. 4, 2020, 5:09 a.m. UTC
When BoundMethodBase::activatePack() is called with the connection type
set to ConnectionTypeDirect, the method isn't deleted even if
deleteMethod is true, as is the case when called from
Object::invokeMethod(). This causes a memory leak. Fix it.

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

Comments

Niklas Söderlund Jan. 7, 2020, 7 p.m. UTC | #1
Hi Laurent,

Thanks for your work.

On 2020-01-04 07:09:36 +0200, Laurent Pinchart wrote:
> When BoundMethodBase::activatePack() is called with the connection type
> set to ConnectionTypeDirect, the method isn't deleted even if
> deleteMethod is true, as is the case when called from
> Object::invokeMethod(). This causes 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/bound_method.cpp | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/libcamera/bound_method.cpp b/src/libcamera/bound_method.cpp
> index 4c0cd415a3f1..45c765774801 100644
> --- a/src/libcamera/bound_method.cpp
> +++ b/src/libcamera/bound_method.cpp
> @@ -62,6 +62,8 @@ void BoundMethodBase::activatePack(void *pack, bool deleteMethod)
>  	case ConnectionTypeDirect:
>  	default:
>  		invokePack(pack);
> +		if (deleteMethod)
> +			delete this;
>  		break;
>  
>  	case ConnectionTypeQueued: {
> -- 
> 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/bound_method.cpp b/src/libcamera/bound_method.cpp
index 4c0cd415a3f1..45c765774801 100644
--- a/src/libcamera/bound_method.cpp
+++ b/src/libcamera/bound_method.cpp
@@ -62,6 +62,8 @@  void BoundMethodBase::activatePack(void *pack, bool deleteMethod)
 	case ConnectionTypeDirect:
 	default:
 		invokePack(pack);
+		if (deleteMethod)
+			delete this;
 		break;
 
 	case ConnectionTypeQueued: {