free_log_history_fix
This commit is contained in:
parent
ccb7d7e118
commit
9b2a43b6d4
2
.vscode/tasks.json
vendored
2
.vscode/tasks.json
vendored
@ -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"
|
||||
|
10
main.c
10
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user