From ed7ccea911cacd816d73fdbc979fdbace764696d Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Mon, 2 May 2016 21:27:38 -0700 Subject: [PATCH] Fix possible NULL deref at quit --- src/gpx/gpx-main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/gpx/gpx-main.c b/src/gpx/gpx-main.c index 5933469..98c2060 100644 --- a/src/gpx/gpx-main.c +++ b/src/gpx/gpx-main.c @@ -66,19 +66,20 @@ static char temp_config_name[24]; static void exit_handler(void) { // close open files - if(file_in != stdin) { + if(file_in != stdin && file_in != NULL) { fclose(file_in); - if(file_out != stdout) { - if(ferror(file_out)) { - perror("Error writing to output file"); - } - fclose(file_out); - file_out = NULL; - } - if(file_out2) { - fclose(file_out2); - file_out2 = NULL; + file_in = NULL; + } + if(file_out != stdout && file_out != NULL) { + if(ferror(file_out)) { + perror("Error writing to output file"); } + fclose(file_out); + file_out = NULL; + } + if(file_out2 != NULL) { + fclose(file_out2); + file_out2 = NULL; } // 23 February 2015