[libvirt PATCH] util/virgdbus: fix memory leak in virGDBusIsServiceInList

Pavel Hrdina posted 1 patch 3 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1721133780306bcf8590cfaf064bdff7b18a2b30.1600869412.git.phrdina@redhat.com
src/util/virgdbus.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[libvirt PATCH] util/virgdbus: fix memory leak in virGDBusIsServiceInList
Posted by Pavel Hrdina 3 years, 7 months ago
g_variant_iter_loop() handles freeing all arguments unless we break out
of the loop, in that case we have to free them manually.

Reported-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util/virgdbus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virgdbus.c b/src/util/virgdbus.c
index cd9ca8d5d6..4360a6acff 100644
--- a/src/util/virgdbus.c
+++ b/src/util/virgdbus.c
@@ -359,8 +359,10 @@ virGDBusIsServiceInList(const char *listMethod,
 
     g_variant_get(reply, "(as)", &iter);
     while (g_variant_iter_loop(iter, "s", &str)) {
-        if (STREQ(str, name))
+        if (STREQ(str, name)) {
+            g_free(str);
             return 0;
+        }
     }
 
     return -2;
-- 
2.26.2

Re: [libvirt PATCH] util/virgdbus: fix memory leak in virGDBusIsServiceInList
Posted by Peter Krempa 3 years, 7 months ago
On Wed, Sep 23, 2020 at 15:57:00 +0200, Pavel Hrdina wrote:
> g_variant_iter_loop() handles freeing all arguments unless we break out
> of the loop, in that case we have to free them manually.
> 
> Reported-by: Peter Krempa <pkrempa@redhat.com>
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/util/virgdbus.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>