From 32bbfac6045d6ab61ff09a6af6daf92fabb45dee Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 31 Oct 2022 15:12:28 +0900 Subject: [PATCH] Deallocate the list memory after using it - Issue: Command list was note deallocated after using it. - Solution: vc_cmd_db module creates the command list for update commands DB, but after using it, the module did not deallocate the list. It can occur memory leak. Thus, this patch adds code for deallocating the list. Change-Id: Iffc7acb78aa577fdd56a27efd1abdc2a802d05eb Signed-off-by: Suyeon Hwang --- common/vc_cmd_db.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 9d572d0..e41b291 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -2488,6 +2488,15 @@ int vc_db_delete_commands(int pid, vc_cmd_type_e type, char* appid) return VC_DB_ERROR_NONE; } +static void __free_command_list_element(gpointer data) +{ + vc_cmd_h temp_cmd = (vc_cmd_h)data; + int ret = vc_cmd_destroy(temp_cmd); + if (ret != VC_ERROR_NONE) { + SLOG(LOG_ERROR, vc_db_tag(), "Fail to destroy command. (%d/%s)", ret, get_error_message(ret)); + } +} + int vc_db_backup_command() { GSList* list = NULL; @@ -2515,13 +2524,13 @@ int vc_db_backup_command() if (ret != VC_DB_ERROR_NONE) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to insert command list to backup db"); __vc_db_rollback_transaction(g_db_backup_handle); - return ret; + } else { + SLOG(LOG_ERROR, vc_db_tag(), "[SUCCESS] Backup commands"); + __vc_db_commit_transaction(g_db_backup_handle); } - __vc_db_commit_transaction(g_db_backup_handle); - - SLOG(LOG_ERROR, vc_db_tag(), "[SUCCESS] Backup commands"); - return VC_DB_ERROR_NONE; + g_slist_free_full(list, __free_command_list_element); + return ret; } int vc_db_restore_command() @@ -2541,10 +2550,11 @@ int vc_db_restore_command() ret = vc_db_insert_commands_list(-1, VC_COMMAND_TYPE_BACKGROUND, list, NULL, true); if (ret != VC_DB_ERROR_NONE) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to insert command list"); - return ret; + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to insert command list. (%d)", ret); + } else { + SLOG(LOG_ERROR, vc_db_tag(), "[SUCCESS] Restore commands"); } - SLOG(LOG_ERROR, vc_db_tag(), "[SUCCESS] Restore commands"); - return VC_DB_ERROR_NONE; + g_slist_free_full(list, __free_command_list_element); + return ret; } -- 2.34.1