[PATCH] client: fix memory leak in client msg

Hao Wang posted 1 patch 3 weeks ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/f605ded8-2190-897b-63bb-cb6b9c07b27b@huawei.com
src/rpc/virnetclient.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

[PATCH] client: fix memory leak in client msg

Posted by Hao Wang 3 weeks ago
>From 3ad3fae4f2562a11bef8dcdd25b6a7e0b00d4e2c Mon Sep 17 00:00:00 2001
From: Hao Wang <wanghao232@huawei.com>
Date: Sat, 18 Jul 2020 15:43:30 +0800
Subject: [PATCH] client: fix memory leak in client msg

When closing client->waitDispatch in virNetClientIOEventLoopRemoveAll
or virNetClientIOEventLoopRemoveDone, VIR_FREE() is called to free
call->msg directly, resulting in leak of the memory call->msg->buffer
points to.
Use virNetMessageFree(call->msg) instead of VIR_FREE(call->msg).

Signed-off-by: Hao Wang <wanghao232@huawei.com>
---
 src/rpc/virnetclient.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 441f1502a6..f899493b64 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -1519,7 +1519,7 @@ static bool virNetClientIOEventLoopRemoveDone(virNetClientCallPtr call,
         if (call->expectReply)
             VIR_WARN("Got a call expecting a reply but without a waiting thread");
         virCondDestroy(&call->cond);
-        VIR_FREE(call->msg);
+        virNetMessageFree(call->msg);
         VIR_FREE(call);
     }

@@ -1546,7 +1546,7 @@ virNetClientIOEventLoopRemoveAll(virNetClientCallPtr call,

     VIR_DEBUG("Removing call %p", call);
     virCondDestroy(&call->cond);
-    VIR_FREE(call->msg);
+    virNetMessageFree(call->msg);
     VIR_FREE(call);
     return true;
 }
--
2.23.0


Re: [PATCH] client: fix memory leak in client msg

Posted by Jonathon Jongsma 3 weeks ago
On Thu, 2020-07-23 at 09:29 +0800, Hao Wang wrote:
> > From 3ad3fae4f2562a11bef8dcdd25b6a7e0b00d4e2c Mon Sep 17 00:00:00
> > 2001
> From: Hao Wang <wanghao232@huawei.com>
> Date: Sat, 18 Jul 2020 15:43:30 +0800
> Subject: [PATCH] client: fix memory leak in client msg
> 
> When closing client->waitDispatch in virNetClientIOEventLoopRemoveAll
> or virNetClientIOEventLoopRemoveDone, VIR_FREE() is called to free
> call->msg directly, resulting in leak of the memory call->msg->buffer
> points to.
> Use virNetMessageFree(call->msg) instead of VIR_FREE(call->msg).
> 
> Signed-off-by: Hao Wang <wanghao232@huawei.com>
> ---
>  src/rpc/virnetclient.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
> index 441f1502a6..f899493b64 100644
> --- a/src/rpc/virnetclient.c
> +++ b/src/rpc/virnetclient.c
> @@ -1519,7 +1519,7 @@ static bool
> virNetClientIOEventLoopRemoveDone(virNetClientCallPtr call,
>          if (call->expectReply)
>              VIR_WARN("Got a call expecting a reply but without a
> waiting thread");
>          virCondDestroy(&call->cond);
> -        VIR_FREE(call->msg);
> +        virNetMessageFree(call->msg);
>          VIR_FREE(call);
>      }
> 
> @@ -1546,7 +1546,7 @@
> virNetClientIOEventLoopRemoveAll(virNetClientCallPtr call,
> 
>      VIR_DEBUG("Removing call %p", call);
>      virCondDestroy(&call->cond);
> -    VIR_FREE(call->msg);
> +    virNetMessageFree(call->msg);
>      VIR_FREE(call);
>      return true;
>  }
> --
> 2.23.0
> 
> 

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>