GNOME Bugzilla – Bug 711016
g_settings_list_keys () segfaults for empty schemas
Last modified: 2013-10-29 05:51:43 UTC
I noticed that pygobject's test case for empty schemas now segfaults. This started to happen recently, 2.38.1 still works fine. Reproducer: * Download https://git.gnome.org/browse/pygobject/tree/tests/org.gnome.test.gschema.xml into /tmp/ * cd /tmp/ * glib-compile-schemas --targetdir=. --schema-file=org.gnome.test.gschema.xml * GSETTINGS_BACKEND=memory GSETTINGS_SCHEMA_DIR=. python -c 'from gi.repository import Gio; s = Gio.Settings("org.gnome.empty"); print(s.list_keys())' On my installed system with glib 2.38.1 this prints "[]" as expected. But in jhbuild, this segfaults: $ GSETTINGS_BACKEND=memory GSETTINGS_SCHEMA_DIR=. jhbuild run gdb --args python -c 'from gi.repository import Gio; s = Gio.Settings("org.gnome.empty"); print(s.list_keys())' Program received signal SIGSEGV, Segmentation fault. 0x00007ffff5577bea in g_settings_schema_list (schema=0xb534a0, n_items=0x7fffffffd0ec) at gsettingsschema.c:1015 1015 for (i = 0; list[i]; i++) In "bt full" it's clear that list is NULL:
+ Trace 232674
Looks like this was introduced with https://git.gnome.org/browse/glib/commit/?id=cbf8cf8598e52 Before that it did len = list ? g_strv_length (list) : 0; which was save against NULL, now it isn't any more.
Created attachment 258316 [details] [review] g_settings_schema_list: some fixes Prevent a crash in the case that gvdb_table_list() returns NULL (ie: because a schema has no keys). Stop a memory leak caused by pointlessly stealing keys from a hashtable (after we quarked them already). Stop allocating an extra entry at the end of an array for a terminator (that we never wrote anyway) when all functions using this API refer to the out-parameter length array.
Review of attachment 258316 [details] [review]: Ok.
Attachment 258316 [details] pushed as 066df98 - g_settings_schema_list: some fixes
Thanks! I confirm that pygobject's test suite works again.