Fix double locking issue 59/225159/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Tue, 18 Feb 2020 01:32:32 +0000 (10:32 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 18 Feb 2020 01:32:32 +0000 (10:32 +0900)
Change-Id: I8d825919a361e0f42c172ae0d9e3f618de081256
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/vc_config_mgr.c

index 76a3bcadd624b598f06695519563c382421afffd..2a3440269d912b3724bccaafb7a1949bb7a70e0d 100644 (file)
@@ -73,6 +73,7 @@ static pthread_mutex_t vc_config_engine_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static int __vc_config_mgr_register_engine_config_updated_event(const char* path);
 static int __vc_config_mgr_unregister_engine_config_updated_event();
+static int __vc_config_mgr_set_default_language(const char* language);
 
 int __vc_config_mgr_print_engine_info();
 int __vc_config_mgr_print_client_info();
@@ -464,7 +465,7 @@ static Eina_Bool __vc_config_mgr_engine_config_inotify_event_callback(void* data
                                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get language");
                        }
 
-                       ret = vc_config_mgr_set_default_language(temp_lang);
+                       ret = __vc_config_mgr_set_default_language(temp_lang);
                        if (0 != ret) {
                                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set language");
                        } else {
@@ -1705,17 +1706,14 @@ int vc_config_mgr_get_default_language(char** language)
        return 0;
 }
 
-int vc_config_mgr_set_default_language(const char* language)
+static int __vc_config_mgr_set_default_language(const char* language)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (0 >= g_slist_length(g_config_client_list)) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (NULL == language) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
@@ -1723,21 +1721,27 @@ int vc_config_mgr_set_default_language(const char* language)
        if (NULL != g_config_info->language) {
                if (0 != vc_parser_set_language(language)) {
                        SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save engine id");
-                       pthread_mutex_unlock(&vc_config_mgr_mutex);
                        return -1;
                }
                free(g_config_info->language);
                g_config_info->language = strdup(language);
        } else {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] language is NULL");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return 0;
 }
 
+int vc_config_mgr_set_default_language(const char* language)
+{
+       pthread_mutex_lock(&vc_config_mgr_mutex);
+       int ret = __vc_config_mgr_set_default_language(language);
+       pthread_mutex_unlock(&vc_config_mgr_mutex);
+
+       return ret;
+}
+
 int vc_config_mgr_get_enabled(bool* value)
 {
        pthread_mutex_lock(&vc_config_mgr_mutex);