[libosinfo PATCH] os: Don't leak scripts list

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

 



osinfo_list_get_elements() calls g_hash_table_get_values() which returns
a GList that must be freed after used.

For more info, please, refer to:
https://developer.gnome.org/glib/unstable/glib-Hash-Tables.html#g-hash-table-get-values

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/osinfo_os.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 4f74331..f89861b 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -611,16 +611,21 @@ OsinfoInstallScript *osinfo_os_find_install_script(OsinfoOs *os, const gchar *pr
     g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
     GList *scripts = osinfo_list_get_elements(OSINFO_LIST(os));
     GList *tmp = scripts;
+    OsinfoInstallScript *s = NULL;
 
     while (tmp) {
         OsinfoInstallScript *script = tmp->data;
-        if (g_str_equal(profile, osinfo_install_script_get_profile(script)))
-            return script;
+        if (g_str_equal(profile, osinfo_install_script_get_profile(script))) {
+            s = script;
+            break;
+        }
 
         tmp = tmp->next;
     }
 
-    return NULL;
+    g_list_free(scripts);
+
+    return s;
 }
 
 
-- 
2.19.1

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




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

  Powered by Linux