From a025c63eecd25b8146d18d446af628e1126e7292 Mon Sep 17 00:00:00 2001
From: Toby Murray <toby.murray@unimelb.edu.au>
Date: Mon, 9 Sep 2019 15:49:41 +1000
Subject: [PATCH] don't have execute close the file, to avoid double-free bug
 in linux

---
 src/passbook.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/src/passbook.c b/src/passbook.c
index 0d5c7bf..9f58f15 100644
--- a/src/passbook.c
+++ b/src/passbook.c
@@ -512,11 +512,9 @@ static int run(FILE *f){
     if (res == NULL){
       if (feof(f)){
         /* end of file */
-        fclose(f);
         return instructionCount;
       }else{
         debug_printf("Error while reading, having read %d lines\n",instructionCount);
-        fclose(f);
         return -1;
       }
     }
@@ -524,7 +522,6 @@ static int run(FILE *f){
       if (!(inst[MAX_LINE_LENGTH] == '\n' && inst[MAX_LINE_LENGTH+1] == '\0')){
         fprintf(stderr,"Line %d exceeds maximum length (%d)\n",instructionCount+1,MAX_LINE_LENGTH);
         debug_printf("(Expected at array index %d to find NUL but found '%c' (%d))\n",MAX_LINE_LENGTH,inst[MAX_LINE_LENGTH],inst[MAX_LINE_LENGTH]);
-        fclose(f);
         return -1;
       }
     }else{
@@ -548,7 +545,6 @@ static int run(FILE *f){
 
   if (feof(f)){
     /* final line of file didn't have a trailing newline */
-    fclose(f);
     return instructionCount;
   }else{
     /* see if we are at end of file by trying to do one more read.
@@ -558,17 +554,14 @@ static int run(FILE *f){
     int res = fread(&c,1,1,f);
     if (res == 1){
       fprintf(stderr,"Number of instructions (lines) in file exceeds max (%d)\n",MAX_INSTRUCTIONS);
-      fclose(f);
       return -1;
     }else{
       if (feof(f)){
         /* final read found the EOF, so all good */
-        fclose(f);
         return instructionCount;
       }else{
         /* probably won't ever get here */
         debug_printf("Error while trying to test if line %d was empty\n",instructionCount+1);
-        fclose(f);
         return -1;
       }
     }
-- 
GitLab