Fix crash when ui-gadget unloads badge module 39/78439/4 accepted/tizen/ivi/20160707.120646 accepted/tizen/mobile/20160707.120556 accepted/tizen/tv/20160707.120611 accepted/tizen/wearable/20160707.120629 submit/tizen/20160706.043533
authorSemun Lee <sm79.lee@samsung.com>
Tue, 5 Jul 2016 12:10:15 +0000 (21:10 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Wed, 6 Jul 2016 06:53:11 +0000 (23:53 -0700)
static variable may cause crash in g_dbus_error_register_error_domain
when the badge module is unloaded by ui-gadget

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

index 141dc55..dcfba0f 100644 (file)
@@ -17,6 +17,7 @@
  *
  */
 
+#include <string.h>
 #include <gio/gio.h>
 #include "badge_error.h"
 
@@ -33,10 +34,26 @@ static const GDBusErrorEntry dbus_error_entries[] = {
        {BADGE_ERROR_INVALID_PACKAGE, "org.freedesktop.Badge.Error.INVALID_PACKAGE"},
 };
 
+#define BADGE_ERROR_QUARK "badge-error-quark"
+
 EXPORT_API GQuark badge_error_quark(void)
 {
        static volatile gsize quark_volatile = 0;
-       g_dbus_error_register_error_domain("badge-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(BADGE_ERROR_QUARK);
+
+       if (quark == 0) {
+               if (domain_name == NULL)
+                       domain_name = strdup(BADGE_ERROR_QUARK);
+       } else {
+               domain_name = BADGE_ERROR_QUARK;
+       }
+
+       g_dbus_error_register_error_domain(domain_name,
                        &quark_volatile,
                        dbus_error_entries,
                        G_N_ELEMENTS(dbus_error_entries));