config: fix infinite loop 97/173497/5
authorBoram Park <boram1288.park@samsung.com>
Thu, 22 Mar 2018 04:44:29 +0000 (13:44 +0900)
committerBoram Park <boram1288.park@samsung.com>
Thu, 22 Mar 2018 09:28:02 +0000 (18:28 +0900)
Change-Id: I8e74042c6cc711e64bc7f932dc2cb66be731872d

src/tdm_config.c

index 703ae0a..fb361d2 100644 (file)
@@ -51,6 +51,7 @@
 
 static pthread_mutex_t g_dic_lock = PTHREAD_MUTEX_INITIALIZER;
 static dictionary *g_dic = NULL;
+static int init_dic = 0;
 
 static int
 _tdm_config_check_file_owner(const char *filepath)
@@ -122,19 +123,19 @@ _tdm_config_check_logs(void)
        pthread_mutex_lock(&g_dic_lock);
 }
 
-static unsigned int
+static void
 _tdm_config_check_init(void)
 {
-       if (g_dic)
-               return 1;
+       if (init_dic)
+               return;
+
+       init_dic = 1;
 
        g_dic = _tdm_config_load_file(TDM_DATA_PATH, TDM_CONFIG_FILENAME);
 
        _tdm_config_check_logs();
 
        TDM_INFO("tdm config init %s (%p)", (g_dic) ? "successed" : "failed", g_dic);
-
-       return (g_dic) ? 1 : 0;
 }
 
 INTERN void
@@ -149,6 +150,7 @@ tdm_config_deinit(void)
 
        iniparser_freedict(g_dic);
        g_dic = NULL;
+       init_dic = 0;
 
        TDM_INFO("tdm config deinit done");
 
@@ -190,7 +192,8 @@ tdm_config_get_int(const char *key, int default_value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %d: default", key, default_value);
                pthread_mutex_unlock(&g_dic_lock);
                return default_value;
@@ -220,7 +223,8 @@ tdm_config_get_string(const char *key, const char *default_value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %s: default", key, default_value);
                pthread_mutex_unlock(&g_dic_lock);
                return default_value;
@@ -246,7 +250,8 @@ tdm_config_set_int(const char *key, int value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %d set failed", key, value);
                pthread_mutex_unlock(&g_dic_lock);
                return TDM_ERROR_BAD_REQUEST;
@@ -272,7 +277,8 @@ tdm_config_set_string(const char *key, const char *value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %s set failed", key, value);
                pthread_mutex_unlock(&g_dic_lock);
                return TDM_ERROR_BAD_REQUEST;