[PATCH 1/2] remote: cleanup properly virDomainDef in ACL helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Technically commit 2ecdf259299813c2c674377e22a0acbce5ccbbb2 does not
really introduces a leak, but it is incorrect ideologically. Neither
function accepting non-const pointer to virDomainDef does not
provide any warrantee that the object will not be improved inside.

Thus, keeping object model in mind, we must ensure that virDomainDefFree
is called over virDomainDef object as a destructor. In order to achieve
this we should change pointer declaration inside
    remoteRelayDomainEventCheckACL
    remoteRelayDomainQemuMonitorEventCheckACL
and assign def->name via strdup.

Fixes: 2ecdf259299813c2c674377e22a0acbce5ccbbb2
Signed-off-by: Denis V. Lunev <den@xxxxxxxxxx>
CC: Peter Krempa <pkrempa@xxxxxxxxxx>
CC: Roman Grigoriev <rgrigoriev@xxxxxxxxxxxxx>
---
 src/remote/remote_daemon_dispatch.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index aaabd1e56c..3172a632df 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -154,14 +154,14 @@ static bool
 remoteRelayDomainEventCheckACL(virNetServerClient *client,
                                virConnectPtr conn, virDomainPtr dom)
 {
-    g_autofree virDomainDef *def = g_new0(virDomainDef, 1);
+    g_autoptr(virDomainDef) def = g_new0(virDomainDef, 1);
     g_autoptr(virIdentity) identity = NULL;
     bool ret = false;
 
     /* For now, we just create a virDomainDef with enough contents to
      * satisfy what viraccessdriverpolkit.c references.  This is a bit
      * fragile, but I don't know of anything better.  */
-    def->name = dom->name;
+    def->name = g_strdup(dom->name);
     memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN);
 
     if (!(identity = virNetServerClientGetIdentity(client)))
@@ -283,14 +283,14 @@ static bool
 remoteRelayDomainQemuMonitorEventCheckACL(virNetServerClient *client,
                                           virConnectPtr conn, virDomainPtr dom)
 {
-    g_autofree virDomainDef *def = g_new0(virDomainDef, 1);
+    g_autoptr(virDomainDef) def = g_new0(virDomainDef, 1);
     g_autoptr(virIdentity) identity = NULL;
     bool ret = false;
 
     /* For now, we just create a virDomainDef with enough contents to
      * satisfy what viraccessdriverpolkit.c references.  This is a bit
      * fragile, but I don't know of anything better.  */
-    def->name = dom->name;
+    def->name = g_strdup(dom->name);
     memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN);
 
     if (!(identity = virNetServerClientGetIdentity(client)))
-- 
2.40.1
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux