Handling hash table NULL case 76/243876/3 accepted/tizen/unified/20200911.143328 submit/tizen/20200911.032314
authorhyunho <hhstark.kang@samsung.com>
Fri, 11 Sep 2020 01:38:35 +0000 (10:38 +0900)
committerhyunho <hhstark.kang@samsung.com>
Fri, 11 Sep 2020 02:18:40 +0000 (11:18 +0900)
In multi-thread environment, hash table can be removed in any context
therefore, we need to check whether the table is NULL or not everytime.

Change-Id: Iedaa5832596981a487972f77fbba1b9e62276469
Signed-off-by: hyunho <hhstark.kang@samsung.com>
widget_viewer_evas/src/widget_viewer_evas.c

index b0e4c6f..b06c091 100644 (file)
@@ -695,6 +695,12 @@ static void __launch_instance()
 
        instance_id = s_info.launch_list->data;
        pthread_mutex_lock(&__mutex);
+       if (s_info.widget_table == NULL) {
+               LOGE("table is null");
+               pthread_mutex_unlock(&__mutex);
+               return;
+       }
+
        info = g_hash_table_lookup(s_info.widget_table, instance_id);
        if (info == NULL) {
                LOGW("can not find instance (%s)", instance_id);
@@ -747,6 +753,12 @@ static void __set_faulted(const char *instance_id)
        struct widget_info *info;
 
        pthread_mutex_lock(&__mutex);
+       if (s_info.widget_table == NULL) {
+               LOGE("table is NULL");
+               pthread_mutex_unlock(&__mutex);
+               return;
+       }
+
        info = g_hash_table_lookup(s_info.widget_table, instance_id);
        if (!info) {
                aul_widget_write_log(LOG_TAG, "[%s:%d] fail to find info (%s)",
@@ -769,6 +781,12 @@ static int __clear_launch_waiting(char *instance_id)
 
        LOGW("Clear launch waiting !! %s", instance_id);
        pthread_mutex_lock(&__mutex);
+       if (s_info.widget_table == NULL) {
+               LOGE("table is NULL");
+               pthread_mutex_unlock(&__mutex);
+               return 0;
+       }
+
        info = g_hash_table_lookup(s_info.widget_table, instance_id);
        if (!info)
                LOGE("Unable to find a proper instance");/* LCOV_EXCL_LINE */
@@ -802,6 +820,12 @@ static int __restart_terminated_widget(const char *widget_id)
        char *id;
 
        pthread_mutex_lock(&__mutex);
+       if (s_info.widget_table == NULL) {
+               LOGE("table is NULL");
+               pthread_mutex_unlock(&__mutex);
+               return 0;
+       }
+
        g_hash_table_iter_init(&iter, s_info.widget_table);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                widget_instance_info = (struct widget_info *)value;
@@ -857,7 +881,6 @@ static int __restart_terminated_widget(const char *widget_id)
 static gboolean __launch_timeout_cb(gpointer user_data)
 {
        char *instance_id = (char *)user_data;
-
        LOGW("Timeout called !! %s", instance_id);
        __clear_launch_waiting(instance_id);
        __set_faulted(instance_id);
@@ -875,6 +898,12 @@ static int __handle_restart_widget_request(const char *widget_id)
        int target_pid = 0;
 
        pthread_mutex_lock(&__mutex);
+       if (s_info.widget_table == NULL) {
+               LOGE("table is NULL");
+               pthread_mutex_unlock(&__mutex);
+               return 0;
+       }
+
        g_hash_table_iter_init(&iter, s_info.widget_table);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                widget_instance_info = (struct widget_info *)value;
@@ -1171,14 +1200,19 @@ API int widget_viewer_evas_fini(void)
                return WIDGET_ERROR_FAULT;
        }
 
+       __remove_launch_timer();
        aul_widget_unset_event_cb();
 
        pthread_mutex_lock(&__mutex);
-       if (s_info.widget_table)
+       if (s_info.widget_table) {
                g_hash_table_destroy(s_info.widget_table);
+               s_info.widget_table = NULL;
+       }
 
-       if (s_info.instance_cnt_table)
+       if (s_info.instance_cnt_table) {
                g_hash_table_destroy(s_info.instance_cnt_table);
+               s_info.instance_cnt_table = NULL;
+       }
        pthread_mutex_unlock(&__mutex);
 
        screen_connector_toolkit_evas_fini(SCREEN_CONNECTOR_SCREEN_TYPE_WIDGET);
@@ -1212,6 +1246,12 @@ API int widget_viewer_evas_notify_resumed_status_of_viewer(void)
                return WIDGET_ERROR_PERMISSION_DENIED;
 
        pthread_mutex_lock(&__mutex);
+       if (s_info.widget_table == NULL) {
+               LOGE("table is NULL");
+               pthread_mutex_unlock(&__mutex);
+               return WIDGET_ERROR_FAULT;
+       }
+
        g_hash_table_iter_init(&iter, s_info.widget_table);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                info = (struct widget_info *)value;
@@ -1601,6 +1641,12 @@ API Evas_Object *widget_viewer_evas_add_widget(Evas_Object *parent, const char *
        }
 
        pthread_mutex_lock(&__mutex);
+       if (s_info.widget_table == NULL || s_info.instance_cnt_table == NULL) {
+               LOGE("table is NULL");
+               pthread_mutex_unlock(&__mutex);
+               return NULL;
+       }
+
        max_instance_cnt = widget_service_get_widget_max_count(widget_id);
        if (max_instance_cnt < 0) {
                set_last_result(WIDGET_ERROR_FAULT);/* LCOV_EXCL_LINE */