free_log_history_fix

This commit is contained in:
s492459 2025-01-04 18:24:13 +01:00
parent ccb7d7e118
commit 9b2a43b6d4
2 changed files with 8 additions and 4 deletions

2
.vscode/tasks.json vendored
View File

@ -7,6 +7,7 @@
"command": "/usr/bin/gcc", "command": "/usr/bin/gcc",
"args": [ "args": [
"-g", "-g",
"-Wall",
"main.c", "main.c",
"-o", "-o",
"a.out" "a.out"
@ -23,6 +24,7 @@
"command": "/usr/bin/gcc", "command": "/usr/bin/gcc",
"args": [ "args": [
"-g", "-g",
"-Wall",
"main_logging.c", "main_logging.c",
"-o", "-o",
"a.out" "a.out"

10
main.c
View File

@ -47,9 +47,11 @@ int LogCommandHistory(char* buf, char** command_log, int* n) {
return 0; return 0;
} }
void FreeCommandHistory(char** command_log, int n) { void FreeCommandHistory(char** command_log) {
for (int i = 0; i < n; i++) { for (int i = 0; i < HISTORY_SIZE; i++) {
free(command_log[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; return 0;
} }