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 563357 a1b313ae2de4425c050346505f83cfad0642acfe
parent 562355 3243c8fc3ce7831dda843b60d6bb2d7e4acf1fd4
child 624439 9e7fc02cb6b81d130761e8aa214ffbd5c6184011
push id54262
push userzbraniecki@mozilla.com
push dateSun, 16 Apr 2017 07:13:20 +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,26 @@ 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);
+  const char * const *schemas = g_settings_list_schemas();
+  GSettings* settings;
+
+  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);
@@ -76,17 +85,17 @@ HourCycle()
         if (strncmp("12", strVal, 2) == 0) {
           rval = 12;
         } else if (strncmp("24", strVal, 2) == 0) {
           rval = 24;
         }
       }
       g_variant_unref(value);
     }
-    g_object_unref(settings);
+		g_object_unref(settings);
   }
   return rval;
 }
 
 /**
  * Since Gtk does not provide a way to customize or format date/time patterns,
  * we're reusing ICU data here, but we do modify it according to the only
  * setting Gtk gives us - hourCycle.