From 13ffac57fa76b431f66c1cc64a9c48577cc609bc Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Tue, 31 Jan 2017 13:41:17 +0900 Subject: [PATCH] Add null checker when memory is released Change-Id: Id77b62236d6f55c07dd71a8ad05cf7655b548903 Signed-off-by: sooyeon.kim --- client/tts.c | 10 ++++-- common/tts_config_mgr.c | 25 +++++++++++--- common/tts_config_parser.c | 81 +++++++++++++++++++++++++++++++++++----------- server/ttsd_data.cpp | 1 + server/ttsd_engine_agent.c | 21 +++++++++--- server/ttsd_server.c | 25 +++++++++++--- 6 files changed, 130 insertions(+), 33 deletions(-) diff --git a/client/tts.c b/client/tts.c index ac1ad4f..3ea3717 100644 --- a/client/tts.c +++ b/client/tts.c @@ -766,8 +766,10 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi ret = tts_config_mgr_get_voice_list(current_engine, __tts_supported_voice_cb, client->tts); - if (NULL != current_engine) + if (NULL != current_engine) { free(current_engine); + current_engine = NULL; + } client->supported_voice_cb = NULL; client->supported_voice_user_data = NULL; @@ -930,6 +932,7 @@ int tts_get_error_message(tts_h tts, char** err_msg) *err_msg = strdup(client->err_msg); SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (%s)", *err_msg); } else { + *err_msg = NULL; SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (NULL)"); } @@ -1072,7 +1075,10 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty } } - if (NULL != temp) free(temp); + if (NULL != temp) { + free(temp); + temp = NULL; + } SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); diff --git a/common/tts_config_mgr.c b/common/tts_config_mgr.c index 10d1952..9faa9ed 100755 --- a/common/tts_config_mgr.c +++ b/common/tts_config_mgr.c @@ -471,6 +471,7 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl if (NULL != before_lang) { free(before_lang); + before_lang = NULL; } } @@ -518,9 +519,18 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl } } - if (NULL != engine) free(engine); - if (NULL != setting) free(setting); - if (NULL != lang) free(lang); + if (NULL != engine) { + free(engine); + engine = NULL; + } + if (NULL != setting) { + free(setting); + setting = NULL; + } + if (NULL != lang) { + free(lang); + lang = NULL; + } } else { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Undefined event"); } @@ -588,6 +598,7 @@ int __tts_config_set_auto_language() char temp_lang[6] = {'\0', }; strncpy(temp_lang, value, 5); free(value); + value = NULL; if (true == __tts_config_mgr_check_lang_is_valid(g_config_info->engine_id, temp_lang, g_config_info->type)) { /* tts default voice change */ @@ -640,6 +651,7 @@ int __tts_config_set_auto_language() if (NULL != before_lang) { free(before_lang); + before_lang = NULL; } } else { /* Display language is not valid */ @@ -941,7 +953,10 @@ static Eina_Bool __tts_config_mgr_engine_config_inotify_event_callback(void* dat } else { SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Saved default voice : lang(%s), type(%d)", g_config_info->language, g_config_info->type); } - if (NULL != temp_lang) free(temp_lang); + if (NULL != temp_lang) { + free(temp_lang); + temp_lang = NULL; + } } GSList *iter = NULL; @@ -1043,6 +1058,7 @@ static int __tts_config_mgr_unregister_engine_config_updated_event() close(tmp->dir_fd); free(tmp); + tmp = NULL; } g_ino_list = g_list_remove_link(g_ino_list, iter); @@ -1193,6 +1209,7 @@ int tts_config_mgr_initialize(int uid) g_config_info->type = tmp_type; free(tmp_language); + tmp_language = NULL; if (0 != tts_parser_set_voice(g_config_info->language, g_config_info->type)) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to save config"); diff --git a/common/tts_config_parser.c b/common/tts_config_parser.c index 17c4a27..f9f5f8d 100755 --- a/common/tts_config_parser.c +++ b/common/tts_config_parser.c @@ -107,7 +107,10 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->name) free(temp->name); + if (NULL != temp->name) { + free(temp->name); + temp->name = NULL; + } temp->name = strdup((char*)key); xmlFree(key); } else { @@ -116,7 +119,10 @@ 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_ID)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->uuid) free(temp->uuid); + if (NULL != temp->uuid) { + free(temp->uuid); + temp->uuid = NULL; + } temp->uuid = strdup((char*)key); xmlFree(key); } else { @@ -125,7 +131,10 @@ 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_SETTING)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->setting) free(temp->setting); + if (NULL != temp->setting) { + free(temp->setting); + temp->setting = NULL; + } temp->setting = strdup((char*)key); xmlFree(key); } else { @@ -164,7 +173,10 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info key = xmlNodeGetContent(voice_node); if (NULL != key) { - if (NULL != temp_voice->language) free(temp_voice->language); + if (NULL != temp_voice->language) { + free(temp_voice->language); + temp_voice->language = NULL; + } temp_voice->language = strdup((char*)key); xmlFree(key); temp->voices = g_slist_append(temp->voices, temp_voice); @@ -215,26 +227,42 @@ int tts_parser_free_engine_info(tts_engine_info_s* engine_info) return -1; } - if (NULL != engine_info->name) free(engine_info->name); - if (NULL != engine_info->uuid) free(engine_info->uuid); - if (NULL != engine_info->setting) free(engine_info->setting); + if (NULL != engine_info->name) { + free(engine_info->name); + engine_info->name = NULL; + } + if (NULL != engine_info->uuid) { + free(engine_info->uuid); + engine_info->uuid = NULL; + } + if (NULL != engine_info->setting) { + free(engine_info->setting); + 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); + if (NULL != temp_voice->language) { + free(temp_voice->language); + temp_voice->language = 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); } - if (NULL != engine_info) free(engine_info); + if (NULL != engine_info) { + free(engine_info); + engine_info = NULL; + } - return 0; + return 0; } int tts_parser_print_engine_info(tts_engine_info_s* engine_info) @@ -258,7 +286,7 @@ int tts_parser_print_engine_info(tts_engine_info_s* engine_info) /* Get a first item */ iter = g_slist_nth(engine_info->voices, 0); - int i = 1; + int i = 1; while (NULL != iter) { /*Get handle data from list*/ temp_voice = iter->data; @@ -359,7 +387,10 @@ int tts_parser_load_config(tts_config_s** config_info) if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->engine_id) free(temp->engine_id); + if (NULL != temp->engine_id) { + free(temp->engine_id); + temp->engine_id = NULL; + } temp->engine_id = strdup((char*)key); xmlFree(key); } else { @@ -368,13 +399,15 @@ int tts_parser_load_config(tts_config_s** config_info) } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->setting) free(temp->setting); + if (NULL != temp->setting) { + free(temp->setting); + temp->setting = NULL; + } temp->setting = strdup((char*)key); xmlFree(key); } else { SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL"); } - } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) { key = xmlNodeGetContent(cur); if (NULL != key) { @@ -412,7 +445,10 @@ int tts_parser_load_config(tts_config_s** config_info) } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->language) free(temp->language); + if (NULL != temp->language) { + free(temp->language); + temp->language = NULL; + } temp->language = strdup((char*)key); xmlFree(key); } else { @@ -826,7 +862,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic if (0 != xmlStrcmp(key_old, key_new)) { SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new); - if (NULL != *engine) free(*engine); + if (NULL != *engine) { + free(*engine); + *engine = NULL; + } *engine = strdup((char*)key_new); } xmlFree(key_new); @@ -845,7 +884,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic if (0 != xmlStrcmp(key_old, key_new)) { SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new); - if (NULL != *setting) free(*setting); + if (NULL != *setting) { + free(*setting); + *setting = NULL; + } *setting = strdup((char*)key_new); } xmlFree(key_new); @@ -886,7 +928,10 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic if (0 != xmlStrcmp(key_old, key_new)) { SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new); - if (NULL != *language) free(*language); + if (NULL != *language) { + free(*language); + *language = NULL; + } *language = strdup((char*)key_new); } xmlFree(key_new); diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index 5ba44aa..b523144 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -284,6 +284,7 @@ int ttsd_data_reset_used_voice(int uid, ttsd_used_voice_cb callback) if (NULL != iter->lang) { free(iter->lang); + iter->lang = NULL; } } diff --git a/server/ttsd_engine_agent.c b/server/ttsd_engine_agent.c index 684a90f..221582b 100644 --- a/server/ttsd_engine_agent.c +++ b/server/ttsd_engine_agent.c @@ -388,7 +388,10 @@ int ttsd_engine_agent_unload_current_engine() data = iter->data; if (NULL != data) { - if (NULL != data->lang) free(data->lang); + if (NULL != data->lang) { + free(data->lang); + data->lang = NULL; + } g_cur_voices = g_slist_remove(g_cur_voices, data); free(data); data = NULL; @@ -691,7 +694,10 @@ int ttsd_engine_agent_set_default_voice(const char* language, int vctype) iter = g_slist_next(iter); } - if (NULL != g_engine_info->default_lang) free(g_engine_info->default_lang); + if (NULL != g_engine_info->default_lang) { + free(g_engine_info->default_lang); + g_engine_info->default_lang = NULL; + } g_engine_info->default_lang = strdup(language); g_engine_info->default_vctype = vctype; @@ -951,7 +957,10 @@ int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, int temp_type; if (true != ttsd_engine_select_valid_voice(lang, vctype, &temp_lang, &temp_type)) { SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to select default voice"); - if (NULL != temp_lang) free(temp_lang); + if (NULL != temp_lang) { + free(temp_lang); + temp_lang = NULL; + } return TTSD_ERROR_INVALID_VOICE; } else { SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent] Start synthesis : language(%s), type(%d), speed(%d), text(%s), credential(%s)", @@ -1171,8 +1180,12 @@ void __free_voice_list(GList* voice_list) data = iter->data; if (NULL != data) { - if (NULL != data->language) free(data->language); + if (NULL != data->language) { + free(data->language); + data->language = NULL; + } free(data); + data = NULL; } voice_list = g_list_remove_link(voice_list, iter); diff --git a/server/ttsd_server.c b/server/ttsd_server.c index c16c183..4cbdd25 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -373,7 +373,10 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_ /* Current language is not available */ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param); } - if (NULL != out_lang) free(out_lang); + if (NULL != out_lang) { + free(out_lang); + out_lang = NULL; + } break; } @@ -709,7 +712,10 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice int temp_type; if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice"); - if (NULL != temp_lang) free(temp_lang); + if (NULL != temp_lang) { + free(temp_lang); + temp_lang = NULL; + } return TTSD_ERROR_INVALID_VOICE; } @@ -722,7 +728,10 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s)); if (NULL == speak_data) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory"); - if (NULL != temp_lang) free(temp_lang); + if (NULL != temp_lang) { + free(temp_lang); + temp_lang = NULL; + } return TTSD_ERROR_OPERATION_FAILED; } @@ -739,7 +748,10 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/ if (0 != ttsd_data_add_speak_data(uid, speak_data)) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data"); - if (NULL != temp_lang) free(temp_lang); + if (NULL != temp_lang) { + free(temp_lang); + temp_lang = NULL; + } if (NULL != speak_data) { if (NULL != speak_data->lang) free(speak_data->lang); if (NULL != speak_data->text) free(speak_data->text); @@ -762,7 +774,10 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice } } - if (NULL != temp_lang) free(temp_lang); + if (NULL != temp_lang) { + free(temp_lang); + temp_lang = NULL; + } if (APP_STATE_PLAYING == state) { /* check if engine use network */ -- 2.7.4