Fix crash when ui-gadget unloads shortcut module 40/78440/2 submit/tizen/20160706.043533
authorSemun Lee <sm79.lee@samsung.com>
Tue, 5 Jul 2016 12:14:55 +0000 (21:14 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Wed, 6 Jul 2016 02:25:47 +0000 (11:25 +0900)
Passing static variable string to g_dbus_error_register_error_domain
may cause crash after ui-gadget unloads shortcut module.

Change-Id: I0f76fe64f6b753f0b8f1bbeb1662b01686f0870b
Signed-off-by: Semun Lee <sm79.lee@samsung.com>
lib/src/shortcut_manager.c

index 002adec7aa8501de465f659299b8a22d7b384229..6c432665ee506c0d7ab776696b7b8681c58d3120 100755 (executable)
@@ -74,10 +74,26 @@ static shortcut_cb_info _callback_info;
 static int _dbus_init();
 static char *_shortcut_get_pkgname_by_pid(void);
 
+#define SHORTCUT_ERROR_QUARK "shortcut-error-quark"
+
 EXPORT_API GQuark shortcut_error_quark(void)
 {
        static volatile gsize quark_volatile = 0;
-       g_dbus_error_register_error_domain("shortcut-error-quark",
+       static char *domain_name = NULL;
+
+       /* This is for preventing crash when notification api is used in ui-gadget     */
+       /* ui-gadget libraries can be unloaded when it is needed and the static string */
+       /* parameter to g_dbus_error_register_error_domain may cause crash.             */
+       GQuark quark = g_quark_try_string(SHORTCUT_ERROR_QUARK);
+
+       if (quark == 0) {
+               if (domain_name == NULL)
+                       domain_name = strdup(SHORTCUT_ERROR_QUARK);
+       } else {
+               domain_name = SHORTCUT_ERROR_QUARK;
+       }
+
+       g_dbus_error_register_error_domain(domain_name,
                        &quark_volatile,
                        dbus_error_entries,
                        G_N_ELEMENTS(dbus_error_entries));