From 7f6a63232f737a50fadfafba63870c83f05d2ffc Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Mon, 18 Nov 2024 18:49:30 +0300 Subject: [PATCH] main.c: close the file on abort and errors --- src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 689eee8..db95a28 100644 --- a/src/main.c +++ b/src/main.c @@ -376,6 +376,9 @@ int main(int argc, char** argv) { if (tolower(character) != 'y') { printf("File corruption aborted.\n"); + + fclose(file); + return EXIT_FAILURE; } } @@ -402,11 +405,15 @@ int main(int argc, char** argv) { if (result == NULL) { PERROR_MACRO("corrupt_file memory allocation"); + fclose(file); + return EXIT_FAILURE; } else if (result->error) { - free(result); PERROR_MACRO("corrupt_file"); + free(result); + fclose(file); + return EXIT_FAILURE; }