Skip to content

Commit ed7ccea

Browse files
committed
Fix possible NULL deref at quit
1 parent d569338 commit ed7ccea

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/gpx/gpx-main.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,20 @@ static char temp_config_name[24];
6666
static void exit_handler(void)
6767
{
6868
// close open files
69-
if(file_in != stdin) {
69+
if(file_in != stdin && file_in != NULL) {
7070
fclose(file_in);
71-
if(file_out != stdout) {
72-
if(ferror(file_out)) {
73-
perror("Error writing to output file");
74-
}
75-
fclose(file_out);
76-
file_out = NULL;
77-
}
78-
if(file_out2) {
79-
fclose(file_out2);
80-
file_out2 = NULL;
71+
file_in = NULL;
72+
}
73+
if(file_out != stdout && file_out != NULL) {
74+
if(ferror(file_out)) {
75+
perror("Error writing to output file");
8176
}
77+
fclose(file_out);
78+
file_out = NULL;
79+
}
80+
if(file_out2 != NULL) {
81+
fclose(file_out2);
82+
file_out2 = NULL;
8283
}
8384

8485
// 23 February 2015

0 commit comments

Comments
 (0)