[PATCH v3 08/12] gsettings: check that children haven't been deleted before using them

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

 



According to the documentation of g_settings_list_children(), the listed
children may be removed at any time, so g_settings_get_child() may
return NULL. This is probably very unlikely to happen in practice, but
it's good to check anyway.
---
 src/modules/gsettings/gsettings-helper.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
index 51f61b009..3bd4b1bab 100644
--- a/src/modules/gsettings/gsettings-helper.c
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -95,8 +95,14 @@ int main(int argc, char *argv[]) {
     group_names = g_settings_list_children(settings);
 
     for (name = group_names; *name; name++) {
-        g_signal_connect(g_settings_get_child(settings, *name), "changed",
-                         (GCallback) module_group_callback, *name);
+        GSettings *child = g_settings_get_child(settings, *name);
+
+        /* The child may have been removed between the
+         * g_settings_list_children() and g_settings_get_child() calls. */
+        if (!child)
+            continue;
+
+        g_signal_connect(child, "changed", (GCallback) module_group_callback, *name);
         handle_module_group(*name);
     }
 
-- 
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