Bug 1356718 - Query gtk settings schemas to avoid crashing when schema is missing. r=jfkthame. a=gchang
authorZibi Braniecki <gandalf@mozilla.com>
Sun, 16 Apr 2017 00:13:07 -0700
changeset 375960 610074e75a49
parent 375959 c5416368f69d
child 375961 04f47021f97c
push id11066
push userihsiao@mozilla.com
push date2017-04-18 08:21 +0000
treeherdermozilla-aurora@b7cdc8cfc61f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame, gchang
bugs1356718
milestone54.0a2
Bug 1356718 - Query gtk settings schemas to avoid crashing when schema is missing. r=jfkthame. a=gchang 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);