Deallocate memory before setting new value 83/283783/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 31 Oct 2022 06:46:54 +0000 (15:46 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Thu, 3 Nov 2022 01:47:52 +0000 (10:47 +0900)
- Issue:
Memory leak can be possible if vc_cmd_db module sets the new value in
vc_cmd_s structure.

- Solution:
The possibility of the issue is because the module did not check the
preivous value of the member. Thus, this patch adds code for checking
the member of the structure. If there is already value set, the module
will release the old value and then set new value.

Change-Id: I2d2676d08a4cacb75c32983c1a49eced28371b65
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/vc_cmd_db.c

index e41b291..154a4fa 100644 (file)
@@ -2185,6 +2185,8 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ
                                        tmp_cmd->command = NULL;
                                }
                                tmp_cmd->command = strdup(temp_command);
+
+                               free(tmp_cmd->fixed);
                                if (NULL != fixed_cmd)
                                        tmp_cmd->fixed = strdup(fixed_cmd);
                                else