[PATCH] rpc: Fix memory leak of fds

Peng Liang posted 1 patch 2 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220302092205.170265-1-liangpeng10@huawei.com
Test syntax-check failed
src/rpc/virnetserver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] rpc: Fix memory leak of fds
Posted by Peng Liang 2 years, 1 month ago
In virSystemdActivationClaimFDs, the memory of ent->fds has been stolen
and stored in fds, but fds is never freed, which causes a memory leak.
Fix it by declaring fds as g_autofree.

Reported-by: Jie Tang <tangjie18@huawei.com>
Signed-off-by: Peng Liang <liangpeng10@huawei.com>
---
 src/rpc/virnetserver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index ad581a36ddf3..d9430a2cfa76 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -655,7 +655,7 @@ virNetServerAddServiceActivation(virNetServer *srv,
                                  size_t max_queued_clients,
                                  size_t nrequests_client_max)
 {
-    int *fds;
+    g_autofree int *fds = NULL;
     size_t nfds;
 
     if (act == NULL)
-- 
2.35.1
Re: [PATCH] rpc: Fix memory leak of fds
Posted by Michal Prívozník 2 years, 1 month ago
On 3/2/22 10:22, Peng Liang wrote:
> In virSystemdActivationClaimFDs, the memory of ent->fds has been stolen
> and stored in fds, but fds is never freed, which causes a memory leak.
> Fix it by declaring fds as g_autofree.
> 
> Reported-by: Jie Tang <tangjie18@huawei.com>
> Signed-off-by: Peng Liang <liangpeng10@huawei.com>
> ---
>  src/rpc/virnetserver.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

and pushed.

Michal