From 9b2a43b6d4a8d47b37819bb516ff4e6898e275f0 Mon Sep 17 00:00:00 2001 From: s492459 Date: Sat, 4 Jan 2025 18:24:13 +0100 Subject: [PATCH] free_log_history_fix --- .vscode/tasks.json | 2 ++ main.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6706c60..3b4598a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,6 +7,7 @@ "command": "/usr/bin/gcc", "args": [ "-g", + "-Wall", "main.c", "-o", "a.out" @@ -23,6 +24,7 @@ "command": "/usr/bin/gcc", "args": [ "-g", + "-Wall", "main_logging.c", "-o", "a.out" diff --git a/main.c b/main.c index 933be2e..2a626ed 100644 --- a/main.c +++ b/main.c @@ -47,9 +47,11 @@ int LogCommandHistory(char* buf, char** command_log, int* n) { return 0; } -void FreeCommandHistory(char** command_log, int n) { - for (int i = 0; i < n; i++) { - free(command_log[i]); +void FreeCommandHistory(char** command_log) { + for (int i = 0; i < HISTORY_SIZE; i++) { + if (command_log[i] != NULL) { + free(command_log[i]); + } } } @@ -270,6 +272,6 @@ int main() { } } - FreeCommandHistory(command_log, n); + FreeCommandHistory(command_log); return 0; } \ No newline at end of file