Resolve unused value and overite problem 87/290187/7
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 21 Mar 2023 07:50:15 +0000 (16:50 +0900)
committerdyamy-lee <dyamy.lee@samsung.com>
Wed, 22 Mar 2023 05:53:29 +0000 (14:53 +0900)
- Issue : coverity reports these as issues. It does free and set NULL, but when assigning value NULL, that stored value is overwritten before it can be used.

- Solution : define value in that value's scope

Change-Id: I53644403ff1595cdfad790d7b454d2b33a0a8e44

common/tts_config_parser.c
engine-parser/src/tts-engine-parser.c
server/ttsd_engine_agent.c

index ed346d52d436daced8f2e9f40d44bdff27084af7..d781688d5db1a292b37dfadde73ad1195576209b 100644 (file)
@@ -72,8 +72,6 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
        bool isTextsize = false;
        xmlDocPtr doc = NULL;
        xmlNodePtr cur = NULL;
-       xmlChar *key = NULL;
-       xmlChar *attr = NULL;
 
        if (0 == access(path, F_OK)) {
                SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", path);
@@ -129,7 +127,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
 
        while (cur != NULL) {
                if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                if (NULL != temp->name) {
                                        free(temp->name);
@@ -142,7 +140,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                if (NULL != temp->uuid) {
                                        free(temp->uuid);
@@ -155,7 +153,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                if (NULL != temp->setting) {
                                        free(temp->setting);
@@ -179,7 +177,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                                break;
                                        }
 
-                                       attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
+                                       xmlChar *attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
                                        if (NULL != attr) {
                                                if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
                                                        temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
@@ -199,7 +197,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                                continue;
                                        }
 
-                                       key = xmlNodeGetContent(voice_node);
+                                       xmlChar *key = xmlNodeGetContent(voice_node);
                                        if (NULL != key) {
                                                if (NULL != temp_voice->language) {
                                                        free(temp_voice->language);
@@ -220,7 +218,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                voice_node = voice_node->next;
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
                                        temp->pitch_support = true;
@@ -232,7 +230,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) {
                        isTextsize = true;
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                temp->text_size = atoi((char*)key);
                                xmlFree(key);
@@ -286,21 +284,23 @@ int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
                engine_info->setting = NULL;
        }
 
-       tts_config_voice_s *temp_voice;
-       temp_voice = g_slist_nth_data(engine_info->voices, 0);
-
-       while (NULL != temp_voice) {
-               if (NULL != temp_voice) {
-                       if (NULL != temp_voice->language) {
-                               free(temp_voice->language);
-                               temp_voice->language = NULL;
+       GSList *iter = NULL;
+       if (g_slist_length(engine_info->voices) > 0) {
+               iter = g_slist_nth(engine_info->voices, 0);
+               while (NULL != iter) {
+                       tts_config_voice_s *temp_voice = (tts_config_voice_s*)iter->data;
+                       if (NULL != temp_voice) {
+                               if (NULL != temp_voice->language) {
+                                       free(temp_voice->language);
+                                       temp_voice->language = NULL;
+                               }
+                               free(temp_voice);
+                               temp_voice = NULL;
                        }
-                       engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
-                       free(temp_voice);
-                       temp_voice = NULL;
-               }
 
-               temp_voice = g_slist_nth_data(engine_info->voices, 0);
+                       engine_info->voices = g_slist_delete_link(engine_info->voices, iter);
+                       iter = g_slist_nth(engine_info->voices, 0);
+               }
        }
 
        if (NULL != engine_info) {
@@ -357,7 +357,6 @@ int tts_parser_load_config(void)
 {
        xmlDocPtr doc = NULL;
        xmlNodePtr cur = NULL;
-       xmlChar *key;
        bool is_default_open = false;
 
        /* For Thread safety */
@@ -458,7 +457,7 @@ int tts_parser_load_config(void)
                                }
                        }
 
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
                                xmlFree(key);
@@ -467,7 +466,7 @@ int tts_parser_load_config(void)
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine id is NULL");
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1);
                                xmlFree(key);
@@ -476,7 +475,7 @@ int tts_parser_load_config(void)
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] setting path is NULL");
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
                                        temp->auto_voice = true;
@@ -493,7 +492,7 @@ int tts_parser_load_config(void)
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
                                        temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
@@ -512,7 +511,7 @@ int tts_parser_load_config(void)
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL");
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                strncpy(temp->language, (char*)key, sizeof(g_language) - 1);
                                xmlFree(key);
@@ -522,7 +521,7 @@ int tts_parser_load_config(void)
                        }
 
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                temp->speech_rate = atoi((char*)key);
                                xmlFree(key);
@@ -530,7 +529,7 @@ int tts_parser_load_config(void)
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] speech rate is NULL");
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                temp->pitch = atoi((char*)key);
                                xmlFree(key);
@@ -539,7 +538,7 @@ int tts_parser_load_config(void)
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
-                       key = xmlNodeGetContent(cur);
+                       xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
                                temp->bg_volume_ratio = atof((char*)key);
                                xmlFree(key);
@@ -883,9 +882,6 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
        xmlNodePtr cur_new = NULL;
        xmlNodePtr cur_old = NULL;
 
-       xmlChar *key_new;
-       xmlChar *key_old;
-
        int retry_count = 0;
        while (NULL == doc) {
                if (0 == access(TTS_CONFIG, F_OK)) {
@@ -933,9 +929,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
        while (cur_new != NULL && cur_old != NULL) {
                if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine id(%s), New engine(%s)",
@@ -957,9 +953,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine setting(%s), New engine setting(%s)",
@@ -981,9 +977,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old auto voice (%s), New auto voice(%s)",
@@ -1005,9 +1001,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old language(%s), New language(%s)",
@@ -1029,9 +1025,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old voice type(%s), New voice type(%s)",
@@ -1057,9 +1053,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old speech rate(%s), New speech rate(%s)",
@@ -1077,9 +1073,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old pitch(%s), New pitch(%s)",
@@ -1097,9 +1093,9 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
-                               key_old = xmlNodeGetContent(cur_old);
+                               xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
-                                       key_new = xmlNodeGetContent(cur_new);
+                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old bg volume ratio(%s), New bg volume ratio(%s)",
index 366e42a59d05847e9ec38b483f571abbd69201a4..d406c4ccd62880e4cf2b4747194d63644fa31d01 100644 (file)
@@ -318,9 +318,8 @@ static void __insert_language_from_metadata(xmlNodePtr root, const char *languag
        LOGD("Add extra voices");
        if (NULL != g_voice_info_list) {
                GSList *iter;
-               voice_info_s *extra_voice = NULL;
                for (iter = g_voice_info_list ; iter != NULL ; iter = g_slist_next(iter)) {
-                       extra_voice = (voice_info_s*)iter->data;
+                       voice_info_s *extra_voice = (voice_info_s*)iter->data;
                        if (NULL != extra_voice) {
                                lang = strdup(extra_voice->lang);
                                type = strdup(extra_voice->type);
@@ -402,8 +401,6 @@ static int __get_voice_inxml()
                        return -1;
                }
 
-               xmlChar *attr = NULL;
-               xmlChar *key = NULL;
 //             char lang[16];
 //             char type[16];
 
@@ -423,7 +420,7 @@ static int __get_voice_inxml()
                                                }
 
                                                LOGD("Get property and keys");
-                                               attr = xmlGetProp(voice_node, (const xmlChar *)TTS_TAG_ENGINE_VOICE_TYPE);
+                                               xmlChar *attr = xmlGetProp(voice_node, (const xmlChar *)TTS_TAG_ENGINE_VOICE_TYPE);
                                                if (NULL != attr) {
 //                                                     strncpy(type, (char*)attr, strlen((char*)attr));
                                                        voice_info->type = strdup((char*)attr);
@@ -434,7 +431,7 @@ static int __get_voice_inxml()
                                                        LOGD("No voice type");
                                                }
 
-                                               key = xmlNodeGetContent(voice_node);
+                                               xmlChar *key = xmlNodeGetContent(voice_node);
                                                if (NULL != key) {
 //                                                     strncpy(lang, (char*)key, strlen((char*)key));
                                                        voice_info->lang = strdup((char*)key);
index eed66c6a89efaca659246cb124b0aeaf4ba1ae9c..1339a6d7b52d00b26b25883c94fc53d7767b87a4 100644 (file)
@@ -1175,7 +1175,6 @@ int ttsd_engine_notify_activated_mode_changed(int activated_mode)
 void __free_voice_list(GList* voice_list)
 {
        GList *iter = NULL;
-       voice_s* data = NULL;
 
        /* if list have item */
        if (g_list_length(voice_list) > 0) {
@@ -1183,7 +1182,7 @@ void __free_voice_list(GList* voice_list)
                iter = g_list_first(voice_list);
 
                while (NULL != iter) {
-                       data = iter->data;
+                       voice_s* data = iter->data;
 
                        if (NULL != data) {
                                if (NULL != data->language) {