[gnome-control-center/wip/applications] Fix a small memory leak



commit 66ae2b0f7691b9bbdad51d2e3f98618cd72aa0b3
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jan 5 17:19:51 2019 -0500

    Fix a small memory leak
    
    When jumping out of a g_variant_iter_loop-driven loop,
    care must be taken to free the variables that are
    managed by that function for regular loop termination.

 panels/applications/cc-applications-panel.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index e5dbce0e9..98d59f248 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -167,8 +167,8 @@ get_flatpak_permissions (CcApplicationsPanel *self,
   g_autoptr(GVariant) ret = NULL;
   g_autoptr(GVariantIter) iter = NULL;
   g_auto(GStrv) permissions = NULL;
-  GVariant *val;
-  gchar *key;
+  g_autoptr(GVariant) val = NULL;
+  g_autofree gchar *key = NULL;
 
   ret = g_dbus_proxy_call_sync (self->perm_store,
                                 "Lookup",
@@ -182,13 +182,13 @@ get_flatpak_permissions (CcApplicationsPanel *self,
   while (g_variant_iter_loop (iter, "{s@as}", &key, &val))
     {
       if (strcmp (key, app_id) == 0)
-        {
-          permissions = g_variant_dup_strv (val, NULL); 
-          break;
-        }
+        return g_variant_dup_strv (val, NULL); 
     }
 
-  return g_steal_pointer (&permissions);
+  val = NULL; /* freed by g_variant_iter_loop */
+  key = NULL;
+
+  return NULL;
 }
 
 static void


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