Fix memory leak / Add type casting 90/117990/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 27 Feb 2017 06:41:42 +0000 (15:41 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 8 Mar 2017 08:13:46 +0000 (00:13 -0800)
Change-Id: I4662a6c54b34717ef0749b8beea9a4d3e2e8d09a
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
(cherry picked from commit ba53ae91923a97f37f3c0020d9e192415fff8430)

common/vc_cmd_db.c
common/vc_command.c
common/vc_config_parser.c
common/vc_info_parser.c
include/voice_control.h
server/vcd_engine_agent.c

index 3cf4094..4218894 100644 (file)
@@ -897,6 +897,20 @@ static int __vc_db_get_result(char** result_text, int* event, char** msg, int pi
        return VC_DB_ERROR_NONE;
 }
 
+void __vc_db_demandable_client_free(void* data)
+{
+       vc_deactivated_app_s* d_app = (vc_deactivated_app_s*)data;
+
+       if (NULL != d_app) {
+               if (NULL != d_app->appid) {
+                       free(d_app->appid);
+                       d_app->appid = NULL;
+               }
+
+               free(d_app);
+       }
+}
+
 static int __vc_db_get_appid(const char* result, GSList** app_list)
 {
        GSList* temp_app_list = NULL;
@@ -940,7 +954,7 @@ static int __vc_db_get_appid(const char* result, GSList** app_list)
                        SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] memory allcation fail");
 
                        if (NULL != temp_app_list) {
-                               g_slist_free_full(temp_app_list, free);
+                               g_slist_free_full(temp_app_list, __vc_db_demandable_client_free);
                                temp_app_list = NULL;
                        }
 
@@ -1225,6 +1239,9 @@ int vc_db_initialize(void)
                        db_util_close(db_handle);
                        db_handle = NULL;
                }
+
+               free(path);
+               path = NULL;
                return VC_DB_ERROR_OPERATION_FAILED;
        }
 
@@ -1234,6 +1251,9 @@ int vc_db_initialize(void)
                if (db_handle)
                        db_util_close(db_handle);
                db_handle = NULL;
+
+               free(path);
+               path = NULL;
                return VC_DB_ERROR_OPERATION_FAILED;
        }
 
@@ -1242,6 +1262,9 @@ int vc_db_initialize(void)
                if (db_handle)
                        db_util_close(db_handle);
                db_handle = NULL;
+
+               free(path);
+               path = NULL;
                return VC_DB_ERROR_OPERATION_FAILED;
        }
 
index 3f3f719..bd0511d 100644 (file)
@@ -1738,7 +1738,12 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
                ret = regexec(&reg[4], str, 2, pmatch, 0);
                if (0 == ret) {
                        len = pmatch[1].rm_eo - pmatch[1].rm_so;
-                       tempstr = strndup(str + pmatch[1].rm_so, len);
+
+                       if (0 > len) {
+                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                               return VC_ERROR_OPERATION_FAILED;
+                       }
+                       tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                        if (NULL == tempstr) {
                                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -1759,7 +1764,12 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
                ret = regexec(&reg[5], str, 2, pmatch, 0);
                if (0 == ret) {
                        len = pmatch[1].rm_eo - pmatch[1].rm_so;
-                       tempstr = strndup(str + pmatch[1].rm_so, len);
+
+                       if (0 > len) {
+                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                               return VC_ERROR_OPERATION_FAILED;
+                       }
+                       tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                        if (NULL == tempstr) {
                                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -1828,7 +1838,12 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
        ret = regexec(&reg[1], str, 2, pmatch, 0);
        if (0 == ret) {
                len = pmatch[1].rm_eo - pmatch[1].rm_so;
-               tempstr = strndup(str + pmatch[1].rm_so, len);
+
+               if (0 > len) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                       return VC_ERROR_OPERATION_FAILED;
+               }
+               tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                if (NULL == tempstr) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -1866,7 +1881,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
                idx = 1;
                len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
                if (0 < len) {
-                       tempstr = strndup(str + pmatch[idx].rm_so, len);
+                       tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len);
 
                        if (NULL == tempstr) {
                                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -2015,7 +2030,12 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
        ret = regexec(&reg[9], str, 2, pmatch, 0);
        if (0 == ret) {
                len = pmatch[1].rm_eo - pmatch[1].rm_so;
-               tempstr = strndup(str + pmatch[1].rm_so, len);
+
+               if (0 > len) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                       return VC_ERROR_OPERATION_FAILED;
+               }
+               tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
 
                if (NULL == tempstr) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
@@ -2079,7 +2099,12 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
                if (!m_flag) return -1;
 
                len = pmatch[2].rm_eo - pmatch[2].rm_so;
-               tempstr = strndup(str + pmatch[2].rm_so, len);
+
+               if (0 > len) {
+                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
+                       return VC_ERROR_OPERATION_FAILED;
+               }
+               tempstr = strndup(str + pmatch[2].rm_so, (size_t)len);
 
                if (NULL == tempstr) {
                        SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
index 050d697..eb9c867 100644 (file)
@@ -225,6 +225,8 @@ int vc_parser_free_engine_info(vc_engine_info_s* engine_info)
                }
        }
 
+       g_slist_free(engine_info->languages);
+
        if (NULL != engine_info)        free(engine_info);
 
        return 0;
index 770ca29..566e83b 100644 (file)
@@ -145,6 +145,20 @@ int vc_cmd_parser_append_commands(int pid, vc_cmd_type_e type, vc_cmd_list_h vc_
        return ret;
 }
 
+void __vc_info_parser_demandable_client_free(void* data)
+{
+       vc_demandable_client_s* d_client = (vc_demandable_client_s*)data;
+
+       if (NULL != d_client) {
+               if (NULL != d_client->appid) {
+                       free(d_client->appid);
+                       d_client->appid = NULL;
+               }
+
+               free(d_client);
+       }
+}
+
 int vc_info_parser_get_demandable_clients(GSList** client_list)
 {
        /* Check file */
@@ -193,7 +207,7 @@ int vc_info_parser_get_demandable_clients(GSList** client_list)
                                        SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Memory alloc error!!");
 
                                        if (NULL != temp_client_list) {
-                                               g_slist_free_full(temp_client_list, free);
+                                               g_slist_free_full(temp_client_list, __vc_info_parser_demandable_client_free);
                                                temp_client_list = NULL;
                                        }
                                        xmlFree(key);
index d8ccd26..154dce9 100644 (file)
@@ -231,7 +231,7 @@ int vc_get_state(vc_state_e* state);
  * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #VC_ERROR_PERMISSION_DENIED Permission denied
  * @retval #VC_ERROR_NOT_SUPPORTED Not supported
- *     @pre The state should be #VC_STATE_READY.
+ * @pre The state should be #VC_STATE_READY.
  * @see vc_request_start()
  * @see vc_request_stop()
  * @see vc_request_cancel()
index 3d9ec29..8166f36 100755 (executable)
@@ -170,10 +170,29 @@ int vcd_engine_agent_release()
                        /* Get handle data from list */
                        data = iter->data;
                        iter = g_list_remove(iter, data);
+
+                       if (NULL != data) {
+                               if (NULL != data->engine_uuid) {
+                                       free(data->engine_uuid);
+                                       data->engine_uuid = NULL;
+                               }
+                               if (NULL != data->engine_name) {
+                                       free(data->engine_name);
+                                       data->engine_name = NULL;
+                               }
+                               if (NULL != data->engine_path) {
+                                       free(data->engine_path);
+                                       data->engine_path = NULL;
+                               }
+
+                               free(data);
+                               data = NULL;
+                       }
                }
        }
 
        g_list_free(iter);
+       g_engine_list = NULL;
 
        /* release current engine data */
        if (NULL != g_dynamic_engine.pefuncs) {
@@ -1133,7 +1152,3 @@ int __log_enginelist()
 
        return 0;
 }
-
-
-
-