Add to release memory for sound data
[platform/core/uifw/tts.git] / common / tts_config_parser.c
index f9f5f8d..82f8428 100755 (executable)
@@ -94,6 +94,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
        if (NULL == temp) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
                xmlFreeDoc(doc);
+               doc = NULL;
                return -1;
        }
 
@@ -113,6 +114,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                }
                                temp->name = strdup((char*)key);
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
                        }
@@ -125,6 +127,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                }
                                temp->uuid = strdup((char*)key);
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
                        }
@@ -137,6 +140,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                }
                                temp->setting = strdup((char*)key);
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
                        }
@@ -164,6 +168,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                                        temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
                                                }
                                                xmlFree(attr);
+                                               attr = NULL;
                                        } else {
                                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
                                                free(temp_voice);
@@ -179,6 +184,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info
                                                }
                                                temp_voice->language = strdup((char*)key);
                                                xmlFree(key);
+                                               key = NULL;
                                                temp->voices = g_slist_append(temp->voices, temp_voice);
                                        } else {
                                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
@@ -326,6 +332,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                doc = xmlParseFile(TTS_DEFAULT_CONFIG);
                if (doc == NULL) {
                        SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
+                       xmlCleanupParser();
                        return -1;
                }
                is_default_open = true;
@@ -342,6 +349,7 @@ int tts_parser_load_config(tts_config_s** config_info)
 
                        if (TTS_RETRY_COUNT == retry_count) {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
+                               xmlCleanupParser();
                                return -1;
                        }
                }
@@ -352,6 +360,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                doc = NULL;
+               xmlCleanupParser();
                return -1;
        }
 
@@ -359,6 +368,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
                xmlFreeDoc(doc);
                doc = NULL;
+               xmlCleanupParser();
                return -1;
        }
 
@@ -367,6 +377,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                doc = NULL;
+               xmlCleanupParser();
                return -1;
        }
 
@@ -376,6 +387,8 @@ int tts_parser_load_config(tts_config_s** config_info)
        if (NULL == temp) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
                xmlFreeDoc(doc);
+               doc = NULL;
+               xmlCleanupParser();
                return -1;
        }
 
@@ -393,6 +406,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                                }
                                temp->engine_id = strdup((char*)key);
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
                        }
@@ -405,6 +419,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                                }
                                temp->setting = strdup((char*)key);
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
                        }
@@ -421,6 +436,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                                }
 
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
                        }
@@ -439,6 +455,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                                }
 
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
                        }
@@ -451,6 +468,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                                }
                                temp->language = strdup((char*)key);
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
                        }
@@ -468,6 +486,7 @@ int tts_parser_load_config(tts_config_s** config_info)
                        if (NULL != key) {
                                temp->pitch = atoi((char*)key);
                                xmlFree(key);
+                               key = NULL;
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
                        }
@@ -525,6 +544,8 @@ int tts_parser_unload_config(tts_config_s* config_info)
                config_info = NULL;
        }
 
+       xmlCleanupParser();
+
        return 0;
 }
 
@@ -554,6 +575,7 @@ int tts_parser_copy_xml(const char* original, const char* destination)
        }
 
        xmlFreeDoc(doc);
+       doc = NULL;
        SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
 
        return 0;
@@ -605,7 +627,7 @@ int tts_parser_set_engine(const char* engine_id, const char* setting, const char
                        default:                                xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);      break;
                        }
                }
-               
+
                cur = cur->next;
        }
 
@@ -869,8 +891,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                        *engine = strdup((char*)key_new);
                                                }
                                                xmlFree(key_new);
+                                               key_new = NULL;
                                        }
                                        xmlFree(key_old);
+                                       key_old = NULL;
                                }
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
@@ -891,8 +915,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                        *setting = strdup((char*)key_new);
                                                }
                                                xmlFree(key_new);
+                                               key_new = NULL;
                                        }
                                        xmlFree(key_old);
+                                       key_old = NULL;
                                }
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
@@ -913,8 +939,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                        }
                                                }
                                                xmlFree(key_new);
+                                               key_new = NULL;
                                        }
                                        xmlFree(key_old);
+                                       key_old = NULL;
                                }
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
@@ -935,8 +963,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                        *language = strdup((char*)key_new);
                                                }
                                                xmlFree(key_new);
+                                               key_new = NULL;
                                        }
                                        xmlFree(key_old);
+                                       key_old = NULL;
                                }
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
@@ -961,8 +991,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                        }
                                                }
                                                xmlFree(key_new);
+                                               key_new = NULL;
                                        }
                                        xmlFree(key_old);
+                                       key_old = NULL;
                                }
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
@@ -979,8 +1011,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                        *speech_rate = atoi((char*)key_new);
                                                }
                                                xmlFree(key_new);
+                                               key_new = NULL;
                                        }
                                        xmlFree(key_old);
+                                       key_old = NULL;
                                }
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
@@ -997,8 +1031,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                        *pitch = atoi((char*)key_new);
                                                }
                                                xmlFree(key_new);
+                                               key_new = NULL;
                                        }
                                        xmlFree(key_old);
+                                       key_old = NULL;
                                }
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");