[libvirt PATCH] virnetdaemon: fix memory leak in virNetDaemonCallInhibit

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/22390d367ddc9665c17c4f5c308853514d63a135.1600871856.git.phrdina@redhat.com
src/rpc/virnetdaemon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[libvirt PATCH] virnetdaemon: fix memory leak in virNetDaemonCallInhibit
Posted by Pavel Hrdina 3 years, 7 months ago
g_variant_new() returns a weak reference which can be consumed by passing
to other g_variant* functions or to g_dbus_connection_call* functions.

This make it possible to call g_variant_new() directly as argument to
the functions above. Because this might be confusing I explicitly call
g_variant_ref_sink() to make it normal reference in both
virGDBusCallMethod() and virGDBusCallMethodWithFD() so the caller is
always responsible for the data.

Reported-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/rpc/virnetdaemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
index f3a5e9f75c..2e01244f74 100644
--- a/src/rpc/virnetdaemon.c
+++ b/src/rpc/virnetdaemon.c
@@ -469,7 +469,7 @@ virNetDaemonCallInhibit(virNetDaemonPtr dmn,
 {
     g_autoptr(GVariant) reply = NULL;
     g_autoptr(GUnixFDList) replyFD = NULL;
-    GVariant *message = NULL;
+    g_autoptr(GVariant) message = NULL;
     GDBusConnection *systemBus;
     int fd;
     int rc;
-- 
2.26.2

Re: [libvirt PATCH] virnetdaemon: fix memory leak in virNetDaemonCallInhibit
Posted by Ján Tomko 3 years, 7 months ago
On a Wednesday in 2020, Pavel Hrdina wrote:
>g_variant_new() returns a weak reference which can be consumed by passing
>to other g_variant* functions or to g_dbus_connection_call* functions.
>
>This make it possible to call g_variant_new() directly as argument to
>the functions above. Because this might be confusing I explicitly call
>g_variant_ref_sink() to make it normal reference in both
>virGDBusCallMethod() and virGDBusCallMethodWithFD() so the caller is
>always responsible for the data.
>
>Reported-by: Peter Krempa <pkrempa@redhat.com>
>Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>---
> src/rpc/virnetdaemon.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
Re: [libvirt PATCH] virnetdaemon: fix memory leak in virNetDaemonCallInhibit
Posted by Peter Krempa 3 years, 7 months ago
On Wed, Sep 23, 2020 at 16:37:48 +0200, Pavel Hrdina wrote:
> g_variant_new() returns a weak reference which can be consumed by passing
> to other g_variant* functions or to g_dbus_connection_call* functions.
> 
> This make it possible to call g_variant_new() directly as argument to
> the functions above. Because this might be confusing I explicitly call
> g_variant_ref_sink() to make it normal reference in both
> virGDBusCallMethod() and virGDBusCallMethodWithFD() so the caller is
> always responsible for the data.
> 
> Reported-by: Peter Krempa <pkrempa@redhat.com>
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---

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