Skip to content
Snippets Groups Projects
Commit a025c63e authored by Toby Murray's avatar Toby Murray
Browse files

don't have execute close the file, to avoid double-free bug in linux

parent 6e1da913
No related branches found
No related tags found
No related merge requests found
...@@ -512,11 +512,9 @@ static int run(FILE *f){ ...@@ -512,11 +512,9 @@ static int run(FILE *f){
if (res == NULL){ if (res == NULL){
if (feof(f)){ if (feof(f)){
/* end of file */ /* end of file */
fclose(f);
return instructionCount; return instructionCount;
}else{ }else{
debug_printf("Error while reading, having read %d lines\n",instructionCount); debug_printf("Error while reading, having read %d lines\n",instructionCount);
fclose(f);
return -1; return -1;
} }
} }
...@@ -524,7 +522,6 @@ static int run(FILE *f){ ...@@ -524,7 +522,6 @@ static int run(FILE *f){
if (!(inst[MAX_LINE_LENGTH] == '\n' && inst[MAX_LINE_LENGTH+1] == '\0')){ 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); 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]); 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; return -1;
} }
}else{ }else{
...@@ -548,7 +545,6 @@ static int run(FILE *f){ ...@@ -548,7 +545,6 @@ static int run(FILE *f){
if (feof(f)){ if (feof(f)){
/* final line of file didn't have a trailing newline */ /* final line of file didn't have a trailing newline */
fclose(f);
return instructionCount; return instructionCount;
}else{ }else{
/* see if we are at end of file by trying to do one more read. /* see if we are at end of file by trying to do one more read.
...@@ -558,17 +554,14 @@ static int run(FILE *f){ ...@@ -558,17 +554,14 @@ static int run(FILE *f){
int res = fread(&c,1,1,f); int res = fread(&c,1,1,f);
if (res == 1){ if (res == 1){
fprintf(stderr,"Number of instructions (lines) in file exceeds max (%d)\n",MAX_INSTRUCTIONS); fprintf(stderr,"Number of instructions (lines) in file exceeds max (%d)\n",MAX_INSTRUCTIONS);
fclose(f);
return -1; return -1;
}else{ }else{
if (feof(f)){ if (feof(f)){
/* final read found the EOF, so all good */ /* final read found the EOF, so all good */
fclose(f);
return instructionCount; return instructionCount;
}else{ }else{
/* probably won't ever get here */ /* probably won't ever get here */
debug_printf("Error while trying to test if line %d was empty\n",instructionCount+1); debug_printf("Error while trying to test if line %d was empty\n",instructionCount+1);
fclose(f);
return -1; return -1;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment