From 91e9f2d20c4c9d33898394c02f807cba7b66eaa6 Mon Sep 17 00:00:00 2001 From: Nate Choe Date: Fri, 22 Apr 2022 23:25:10 -0500 Subject: [PATCH] Fixed double free --- src/html.c | 6 ++++-- src/main.c | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/html.c b/src/html.c index 390b5f2..8a14f7c 100644 --- a/src/html.c +++ b/src/html.c @@ -32,13 +32,13 @@ int copyhtml(FILE *in, FILE *out) { addspace = 0; c = fgetc(in); if (c == EOF) - return 0; + goto end; if (isspace(c)) { addspace = 1; while (isspace(c)) { c = fgetc(in); if (c == EOF) - return 0; + goto end; } } if (c == '<' || c == '>') { @@ -52,5 +52,7 @@ int copyhtml(FILE *in, FILE *out) { fputc(c, out); } } +end: + fclose(in); return 0; } diff --git a/src/main.c b/src/main.c index 128fc7d..dde1bd2 100644 --- a/src/main.c +++ b/src/main.c @@ -67,14 +67,12 @@ int main(int argc, char **argv) { fputs("Failed to copy header\n", stderr); return 1; } - fclose(headerfile); } if (template != NULL) { FILE *templatefile; templatefile = fopen(template, "r"); if (parsetemplate(templatefile, outfile)) return 1; - fclose(templatefile); } if (footer != NULL) { FILE *footerfile; @@ -83,7 +81,6 @@ int main(int argc, char **argv) { fputs("Failed to copy footer\n", stderr); return 1; } - fclose(footerfile); } if (outfile != stdout) fclose(outfile);