[libvirt-designer 3/4] virtxml: Fix various memory leaks

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

 



All memory was not cleaned up properly upon exit, and a string
could be leaked from guess_os_from_disk when we issue a
continue/break early during the loop iteration.
---
 examples/virtxml.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/examples/virtxml.c b/examples/virtxml.c
index d719e5f..e577911 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -369,6 +369,10 @@ guess_os_from_disk(GList *disk_list)
             path = g_strndup(path, sep-path);
 
         media = osinfo_media_create_from_location(path, NULL, NULL);
+
+        if (sep)
+            g_free(path);
+
         if (!media)
             continue;
 
@@ -376,9 +380,6 @@ guess_os_from_disk(GList *disk_list)
             g_object_get(G_OBJECT(media), "os", &ret, NULL);
             break;
         }
-
-        if (sep)
-            g_free(path);
     }
 
     return ret;
@@ -595,12 +596,22 @@ main(int argc, char *argv[])
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(config));
 
     g_printf("%s\n", xml);
+    g_free(xml);
 
     ret = EXIT_SUCCESS;
 
 cleanup:
+    if (os)
+        g_object_unref(G_OBJECT(os));
+    if (platform)
+        g_object_unref(G_OBJECT(platform));
+    if (caps)
+        g_object_unref(G_OBJECT(caps));
+    if (domain)
+        g_object_unref(G_OBJECT(domain));
     if (conn)
         gvir_connection_close(conn);
+
     return ret;
 }
 
-- 
1.8.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]