From f71e51fb87d8ff9d3f651c8b8133db3c6992d2f9 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Tue, 1 Dec 2020 13:36:46 +0900 Subject: [PATCH] Fix defects from static analysis tool Change-Id: Ib30853516b665e935974b938b6217df583f7510e --- client/vc.c | 91 ++++++++++++++++---------------------------------------- common/vc_main.h | 4 +++ 2 files changed, 30 insertions(+), 65 deletions(-) diff --git a/client/vc.c b/client/vc.c index f5ed34d..2cb5930 100644 --- a/client/vc.c +++ b/client/vc.c @@ -128,8 +128,7 @@ static int __check_privilege(const char* uid, const char * privilege) char *session = cynara_session_from_pid(pid); int ret = cynara_check(p_cynara, smack_label, session, uid, privilege); SLOG(LOG_DEBUG, TAG_VCC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied"); - if (session) - free(session); + FREE(session); if (ret != CYNARA_API_ACCESS_ALLOWED) return false; //LCOV_EXCL_LINE @@ -1095,10 +1094,7 @@ static int __vc_get_invocation_name(char** invocation_name) if (0 != ret || NULL == appid) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get appid, ret(%d)", ret); //LCOV_EXCL_LINE - if (NULL != appid) { - free(appid); - appid = NULL; - } + FREE(appid); return VC_ERROR_OPERATION_FAILED; //LCOV_EXCL_STOP } @@ -1106,12 +1102,8 @@ static int __vc_get_invocation_name(char** invocation_name) ret = vc_get_current_language(&lang); if (0 != ret || NULL == lang) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get current language, ret(%d)", ret); //LCOV_EXCL_LINE - free(appid); - appid = NULL; - if (NULL != lang) { - free(lang); - lang = NULL; - } + FREE(appid); + FREE(lang); return VC_ERROR_OPERATION_FAILED; } @@ -1119,14 +1111,9 @@ static int __vc_get_invocation_name(char** invocation_name) if (0 != ret || NULL == temp_label) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get localed label, ret(%d) appid(%s) lang(%s)", ret, appid, lang); //LCOV_EXCL_LINE - free(appid); - appid = NULL; - free(lang); - lang = NULL; - if (NULL != temp_label) { - free(temp_label); - temp_label = NULL; - } + FREE(appid); + FREE(lang); + FREE(temp_label); return VC_ERROR_OPERATION_FAILED; //LCOV_EXCL_STOP } @@ -1134,15 +1121,15 @@ static int __vc_get_invocation_name(char** invocation_name) *invocation_name = strdup(temp_label); if (NULL == *invocation_name) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE + FREE(appid); + FREE(lang); + FREE(temp_label); return VC_ERROR_OUT_OF_MEMORY; } - free(appid); - appid = NULL; - free(lang); - lang = NULL; - free(temp_label); - temp_label = NULL; + FREE(appid); + FREE(lang); + FREE(temp_label); } SLOG(LOG_DEBUG, TAG_VCC, "Get invocation name(%s)", *invocation_name); @@ -1241,10 +1228,7 @@ int vc_set_command_list(vc_cmd_list_h vc_cmd_list, int type) } while (0 != ret); } - if (NULL != invocation_name) { - free(invocation_name); - invocation_name = NULL; - } + FREE(invocation_name); if (VC_COMMAND_TYPE_BACKGROUND == type) g_backup = true; @@ -1397,10 +1381,7 @@ int vc_set_command_list_from_file(const char* file_path, int type) } while (0 != ret); } - if (NULL != invocation_name) { - free(invocation_name); - invocation_name = NULL; - } + FREE(invocation_name); SLOG(LOG_DEBUG, TAG_VCC, "@@@"); return ret; @@ -1784,9 +1765,7 @@ static Eina_Bool __vc_notify_result(void *data) vc_cmd_list = NULL; /* Release result */ - if (temp_text) - free(temp_text); - temp_text = NULL; + FREE(temp_text); return EINA_FALSE; } @@ -1856,10 +1835,7 @@ int vc_get_result(vc_result_cb callback, void* user_data) vc_cmd_list = NULL; /* Release result */ - if (NULL != temp_text) { - free(temp_text); - temp_text = NULL; - } + FREE(temp_text); SLOG(LOG_DEBUG, TAG_VCC, "@@@"); @@ -2264,8 +2240,7 @@ int vc_set_server_dialog(const char* app_id, const char* credential) ret = app_manager_get_app_id(getpid(), &tmp_appid); if (0 != ret || NULL == tmp_appid) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] app_id is NULL"); - if (NULL != tmp_appid) - free(tmp_appid); + FREE(tmp_appid); return VC_ERROR_INVALID_PARAMETER; } } else { @@ -2301,9 +2276,7 @@ int vc_set_server_dialog(const char* app_id, const char* credential) } } while (0 != ret); - - if (NULL != tmp_appid) - free(tmp_appid); + FREE(tmp_appid); SLOG(LOG_DEBUG, TAG_VCC, "@@@"); @@ -2350,8 +2323,7 @@ int vc_unset_server_dialog(const char* app_id) ret = app_manager_get_app_id(getpid(), &tmp_appid); if (0 != ret || NULL == tmp_appid) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] app_id is NULL"); - if (NULL != tmp_appid) - free(tmp_appid); + FREE(tmp_appid); return VC_ERROR_INVALID_PARAMETER; } } else { @@ -2388,11 +2360,8 @@ int vc_unset_server_dialog(const char* app_id) } } while (0 != ret); - - if (NULL != tmp_appid) - free(tmp_appid); - if (NULL != credential) - free(credential); + FREE(tmp_appid); + FREE(credential); SLOG(LOG_DEBUG, TAG_VCC, "@@@"); @@ -2946,12 +2915,10 @@ static void __start_tts_streaming_thread(void* data, Ecore_Thread* thread) /* If no tts data and EVENT_FINISH */ if (0 >= vc_data_get_tts_data_size() && VC_TTS_EVENT_FINISH == tts_data->event) { SLOG(LOG_INFO, TAG_VCC, "[INFO] Finish tts"); - free(tts_data); - tts_data = NULL; + FREE(tts_data) break; } - free(tts_data); - tts_data = NULL; + FREE(tts_data); } } } @@ -2995,14 +2962,8 @@ int __vc_cb_tts_streaming(int utt_id, vc_tts_event_e event, char* buffer, int le int ret = vc_data_add_tts_data(temp_tts_data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to add tts data"); - if (NULL != temp_tts_data->data) { - free(temp_tts_data->data); - temp_tts_data->data = NULL; - } - if (NULL != temp_tts_data) { - free(temp_tts_data); - temp_tts_data = NULL; - } + FREE(temp_tts_data->data); + FREE(temp_tts_data); } bool is_canceled = ecore_thread_check(g_tts_thread); diff --git a/common/vc_main.h b/common/vc_main.h index 061155e..9ed4128 100644 --- a/common/vc_main.h +++ b/common/vc_main.h @@ -53,6 +53,10 @@ struct vc_s { typedef struct vc_s *vc_h; +/* Define Macro */ +#define FREE(x) { if (NULL != x) { free(x); x = NULL; } } +#define G_FREE(x) { if (NULL != x) { g_free(x); x = NULL; } } + #ifdef __cplusplus } #endif -- 2.7.4