gsettings: free the module-group GSettings objects after use
authorTanu Kaskinen <tanuk@iki.fi>
Tue, 17 Apr 2018 06:07:40 +0000 (09:07 +0300)
committerTanu Kaskinen <tanuk@iki.fi>
Thu, 19 Apr 2018 11:45:19 +0000 (14:45 +0300)
g_settings_get_child() returns a new GSettings object that needs to be
freed when it's not used any more. This patch collects all the childern
to a GPtrArray and frees them at the end of main(). They can't be freed
earlier, because that would prevent the "changed" signals from being
delivered.

src/modules/gsettings/gsettings-helper.c

index cf047e2..120456b 100644 (file)
@@ -79,6 +79,7 @@ static void module_group_callback(GSettings *settings, gchar *key, gpointer user
 int main(int argc, char *argv[]) {
     GMainLoop *g;
     GSettings *settings;
+    GPtrArray *groups;
     gchar **group_names, **name;
 
 #if !GLIB_CHECK_VERSION(2,36,0)
@@ -88,6 +89,7 @@ int main(int argc, char *argv[]) {
     if (!(settings = g_settings_new(PA_GSETTINGS_MODULE_GROUPS_SCHEMA)))
         goto fail;
 
+    groups = g_ptr_array_new_full(0, g_object_unref);
     group_names = g_settings_list_children(settings);
 
     for (name = group_names; *name; name++) {
@@ -98,6 +100,7 @@ int main(int argc, char *argv[]) {
         if (!child)
             continue;
 
+        g_ptr_array_add(groups, child);
         g_signal_connect(child, "changed", (GCallback) module_group_callback, *name);
         handle_module_group(*name);
     }
@@ -110,6 +113,7 @@ int main(int argc, char *argv[]) {
     g_main_loop_run(g);
     g_main_loop_unref(g);
 
+    g_ptr_array_unref(groups);
     g_object_unref(G_OBJECT(settings));
 
     return 0;