Fix defects from static analysis tool 32/248632/1 submit/tizen/20201201.045614
authorwn.jang <wn.jang@samsung.com>
Tue, 1 Dec 2020 04:36:46 +0000 (13:36 +0900)
committerwn.jang <wn.jang@samsung.com>
Tue, 1 Dec 2020 04:51:51 +0000 (13:51 +0900)
Change-Id: Ib30853516b665e935974b938b6217df583f7510e

client/vc.c
common/vc_main.h

index f5ed34d978acd78c938822b235ae28a93487a7fd..2cb5930f863a06022da5eed9653df2eb303d6bc4 100644 (file)
@@ -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);
index 061155ef174b291bca8bc8c9e6a9def2cc7d137c..9ed41285e3e7770ec01950cac3067007a163c41d 100644 (file)
@@ -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