[PATCH v3 10/12] gsettings: free the module-group GSettings objects after use

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

 



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 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
index f000e85e5..ae9dc45eb 100644
--- a/src/modules/gsettings/gsettings-helper.c
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -81,6 +81,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)
@@ -90,6 +91,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++) {
@@ -100,6 +102,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);
     }
@@ -112,6 +115,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;
-- 
2.16.3



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux