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
Branches
No related tags found
No related merge requests found
......@@ -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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment