commit: 9138dac995b7d5edb359d439784585746754e2c4
parent ee78345f0a2e2c7ef340b7b54bc8e8b6c531b209
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 22 Sep 2025 05:24:20 +0200
cmd/wc: fix missing file close in -m mode
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/cmd/wc.c b/cmd/wc.c
@@ -13,7 +13,7 @@
#include <locale.h> // setlocale
#include <stdbool.h>
#include <stdint.h> // uint8_t
-#include <stdio.h> // fprintf, fopen
+#include <stdio.h> // fprintf
#include <stdlib.h> // abort
#include <string.h> // strchr, strerror
#include <sys/stat.h>
@@ -174,6 +174,7 @@ wc_file_chars(int fd, char *filename)
while(true)
{
+ errno = 0;
wint_t c = getwc(file);
if(c == WEOF)
{
@@ -184,6 +185,9 @@ wc_file_chars(int fd, char *filename)
argv0,
filename != NULL ? filename : "<stdin>",
strerror(errno));
+
+ fclose(file);
+
return -1;
}
break;
@@ -210,6 +214,7 @@ wc_file_chars(int fd, char *filename)
print_counts(lines, words, chars, filename);
+ fclose(file);
return 0;
}