Bug 1356718 - Query gtk settings schemas to avoid crashing when schema is missing. r=jfkthame draft
authorZibi Braniecki <gandalf@mozilla.com>
Sun, 16 Apr 2017 00:13:07 -0700
changeset 563707 a6f20cefa04c37bf73574f9065a63e375891bd03
parent 563410 c697e756f738ce37abc56f31bfbc48f55625d617
child 624552 05e86527db3cfa8c05aa55434ded317b438ce1e2
push id54393
push userzbraniecki@mozilla.com
push dateMon, 17 Apr 2017 15:51:01 +0000
reviewersjfkthame
bugs1356718
milestone55.0a1
Bug 1356718 - Query gtk settings schemas to avoid crashing when schema is missing. r=jfkthame MozReview-Commit-ID: 2rqO4XpLbfO
intl/locale/gtk/OSPreferences_gtk.cpp
--- a/intl/locale/gtk/OSPreferences_gtk.cpp
+++ b/intl/locale/gtk/OSPreferences_gtk.cpp
@@ -56,17 +56,30 @@ HourCycle()
   if (env && strcmp(env, "Unity") == 0) {
     schema = "com.canonical.indicator.datetime";
     key = "time-format";
   } else {
     schema = "org.gnome.desktop.interface";
     key = "clock-format";
   }
 
-  GSettings* settings = g_settings_new(schema);
+  // This is a workaround for old GTK versions.
+  // Once we bump the minimum version to 2.40 we should replace
+  // this with g_settings_schme_source_lookup.
+  // See bug 1356718 for details.
+  const char* const* schemas = g_settings_list_schemas();
+  GSettings* settings = nullptr;
+
+  for (uint32_t i = 0; schemas[i] != nullptr; i++) {
+    if (strcmp(schemas[i], schema) == 0) {
+      settings = g_settings_new(schema);
+      break;
+    }
+  }
+
   if (settings) {
     // We really want to use g_settings_get_user_value which will
     // only want to take it if user manually changed the value.
     // But this requires glib 2.40, and we still support older glib versions,
     // so we have to check whether it's available and fall back to the older
     // g_settings_get_value if not.
     static get_value_fn_t sGetValueFunction = FindGetValueFunction();
     GVariant* value = sGetValueFunction(settings, key);