gsettings: check that children haven't been deleted before using them

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.
This commit is contained in:
Tanu Kaskinen 2018-04-17 09:07:38 +03:00
parent f5ff5d8bf2
commit 8484b63c18

View file

@ -93,8 +93,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);
}