From 0af428185dd1ca73befa815130e14b0a15c6f91b Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Mon, 25 Nov 2019 10:38:27 +0900 Subject: [PATCH] Fix memory leak issue using g_slist Change-Id: Ib37e5f748ef821eafb53b08e1a4093928ed39311 (cherry picked from commit f75ef72ecd870c338c8e6a1dce2deab589bd55dc) --- server/vcd_server.c | 89 +++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/server/vcd_server.c b/server/vcd_server.c index b1d5717..d632034 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -303,6 +303,21 @@ static bool __vcd_is_package_installed(const char* appid) return true; } +void __vc_free_deactivated_app(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); + d_app = NULL; + } +} + static bool __vcd_launch_app(const char* result) { if (NULL == result) { @@ -325,54 +340,43 @@ static bool __vcd_launch_app(const char* result) while (NULL != iter) { temp_app = iter->data; - if (NULL != temp_app) { - if (NULL != temp_app->appid) { - int ret = -1; - bool running = false; - ret = app_manager_is_running(temp_app->appid, &running); - if (APP_MANAGER_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid); - free(temp_app->appid); - temp_app->appid = NULL; - free(temp_app); - temp_app = NULL; - return VCD_ERROR_OPERATION_FAILED; - } - if (false == running) { - int tmp_ret = __vcd_is_package_installed(temp_app->appid); - if (false == tmp_ret) { - SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid); - } else { - ret = __vcd_activate_app_by_appcontrol(temp_app->appid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app"); - free(temp_app->appid); - temp_app->appid = NULL; - free(temp_app); - temp_app = NULL; - return ret; - } - SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result); - } + if (NULL != temp_app && NULL != temp_app->appid) { + int ret = -1; + bool running = false; + ret = app_manager_is_running(temp_app->appid, &running); + if (APP_MANAGER_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid); + g_slist_free_full(iter, __vc_free_deactivated_app); + return VCD_ERROR_OPERATION_FAILED; + } + if (false == running) { + int tmp_ret = __vcd_is_package_installed(temp_app->appid); + if (false == tmp_ret) { + SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid); } else { - ret = __vcd_resume_app(temp_app->appid); + ret = __vcd_activate_app_by_appcontrol(temp_app->appid); if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app"); - free(temp_app->appid); - temp_app->appid = NULL; - free(temp_app); - temp_app = NULL; + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app"); + g_slist_free_full(iter, __vc_free_deactivated_app); return ret; } - SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result); + SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result); } - free(temp_app->appid); - temp_app->appid = NULL; + } else { + ret = __vcd_resume_app(temp_app->appid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app"); + g_slist_free_full(iter, __vc_free_deactivated_app); + return ret; + } + SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result); } - free(temp_app); + __vc_free_deactivated_app((void*)temp_app); temp_app = NULL; } - iter = g_slist_next(iter); + app_list = g_slist_remove_link(app_list, iter); + g_slist_free(iter); + iter = g_slist_nth(app_list, 0); } app_list = NULL; } @@ -409,6 +413,8 @@ static Eina_Bool __vcd_send_selected_result(void *data) ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type); if (0 != ret) { SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret); + g_slist_free_full(pid_list, free); + pid_list = NULL; break; } else { SLOG(LOG_ERROR, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type); @@ -420,6 +426,7 @@ static Eina_Bool __vcd_send_selected_result(void *data) temp_cmd = NULL; } pid_list = g_slist_remove_link(pid_list, iter); + g_slist_free(iter); iter = g_slist_nth(pid_list, 0); } } @@ -3268,4 +3275,4 @@ int vcd_set_tts_audio_format_request_cb(vce_tts_audio_format_request_cb callback } return ret; -} +} \ No newline at end of file -- 2.7.4