Fix crash of ug-client apps 40/78940/7 accepted/tizen/common/20160707.172213 accepted/tizen/ivi/20160707.225154 accepted/tizen/mobile/20160707.225105 accepted/tizen/tv/20160707.225121 accepted/tizen/wearable/20160707.225137 submit/tizen/20160707.122156
authorSemun Lee <sm79.lee@samsung.com>
Thu, 7 Jul 2016 11:10:16 +0000 (20:10 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Thu, 7 Jul 2016 12:21:00 +0000 (21:21 +0900)
dlopen ug shared library file again to prevent crash while terminating app.
In some case, unloaded memory could be accessed by other libaries clean up routine.

Fix double free of ad.name

Change-Id: I612c318ccb798d76a0ac8b77ab8f23dbe2b1e974
Signed-off-by: Semun Lee <sm79.lee@samsung.com>
client/ug-client.c
include/ug-module.h
src/module.c
src/ug.c

index 38fe98fc0bf93a77cb0eb65b82976c3124e4413f..bce59d5ea7bc5d10f331517540a076b5230087f1 100644 (file)
  */
 
 #include <stdio.h>
+#include <dlfcn.h>
+#include <errno.h>
 #include <appcore-efl.h>
 #include <ui-gadget.h>
+#include <ug-module.h>
 
 #include <dlog.h>
 #include <aul.h>
@@ -492,9 +495,22 @@ func_out:
 static int app_terminate(void *data)
 {
        struct appdata *ad = data;
+       char *ug_file_path = NULL;
+       void *handle;
+       int ret;
 
        LOGD("app_terminate called");
 
+       ret = ug_module_get_file_path(ad->name, &ug_file_path);
+       if (ret == 0) {
+               handle = dlopen(ug_file_path, RTLD_LAZY);
+               if (!handle)
+                       LOGE("Failed to dlopen the ug file (%d)", errno);
+       }
+
+       if (ug_file_path)
+               free(ug_file_path);
+
        _ug_client_dbus_signal_handler_fini(data);
 
        evas_object_smart_callback_del(ad->win, "wm,rotation,changed", rotate);
@@ -513,9 +529,6 @@ static int app_terminate(void *data)
 
        app_control_destroy(ad->request);
 
-       if (ad->name)
-               free(ad->name);
-
        LOGD("app_terminate end");
 
        return 0;
index 2db135fd0e63ae569b9075bf3988e83d839a3373..36811d4e7281a421f707a1f9b0cff023e551df80 100644 (file)
@@ -33,6 +33,6 @@ struct ug_module {
 
 struct ug_module *ug_module_load(const char *name);
 int ug_module_unload(struct ug_module *module);
-int ug_exist(const char* name);
+int ug_module_get_file_path(const char *name, char **ug_file_path);
 
 #endif                         /* __UG_MODULE_H__ */
index 2df10e29c9c3124709aaf6a46d37d473c588adbd..b66e772c2cd3988a783b3dce7e7758bb26ff2c2e 100644 (file)
 #define MEM_ADDR_LEN 8
 #define MEM_ADDR_TOT_LEN 17
 
+#ifndef UG_API
+#define UG_API __attribute__ ((visibility("default")))
+#endif
+
+
 static char *__ug_module_get_addr(const char *ug_name)
 {
        FILE *file;
@@ -278,14 +283,12 @@ int ug_module_unload(struct ug_module *module)
        return 0;
 }
 
-int ug_exist(const char* name)
+UG_API int ug_module_get_file_path(const char *name, char **ug_file_path)
 {
-       int ret = 1;
-
-       if (__get_ug_info(name, NULL) < 0) {
+       if (__get_ug_info(name, ug_file_path) < 0) {
                _ERR("error in getting ug file path");
-               ret = 0;
+               return -1;
        }
 
-       return ret;
+       return 0;
 }
index ad4bcf4bb2f874ea7681b756f9df40e5680080b5..604523792a628a031904ff3245ee51aecf226396 100644 (file)
--- a/src/ug.c
+++ b/src/ug.c
@@ -377,12 +377,21 @@ UG_API int ug_disable_effect(ui_gadget_h ug)
 
 UG_API int ug_is_installed(const char *name)
 {
+       int ret = 1;
+       char *ug_file_path = NULL;
+
        if (name == NULL) {
                _ERR("name is null");
                return -1;
        }
 
-       return ug_exist(name);
+       if (!ug_module_get_file_path(name, &ug_file_path))
+               ret = 0;
+
+       if (ug_file_path)
+               free(ug_file_path);
+
+       return ret;
 }
 
 #ifdef ENABLE_UG_CREATE_CB