@@ -25,19 +25,22 @@ void highsOpenLogFile(HighsLogOptions& log_options,
2525 OptionStatus status =
2626 getOptionIndex (log_options, " log_file" , option_records, index);
2727 assert (status == OptionStatus::kOk );
28- if (log_options.log_stream != NULL ) {
28+ if (log_options.log_stream != nullptr ) {
2929 // Current log file stream is not null, so flush and close it
3030 fflush (log_options.log_stream );
3131 fclose (log_options.log_stream );
32+ // Set the stream to null to give a test whether it has been
33+ // closed (and avoid trying to close it again which causes an
34+ // error)
35+ log_options.log_stream = nullptr ;
3236 }
33- if (log_file.compare (" " )) {
34- // New log file name is not empty, so open it, appending if
35- // possible
37+ assert (!log_options.log_stream );
38+ // If new log file name is not empty, open it, appending if possible
39+ //
40+ // If fopen fails then it returns nullptr, so log_file is open for
41+ // writing or nullptr
42+ if (log_file.compare (" " ))
3643 log_options.log_stream = fopen (log_file.c_str (), " a" );
37- } else {
38- // New log file name is empty, so set the stream to null
39- log_options.log_stream = NULL ;
40- }
4144 OptionRecordString& option = *(OptionRecordString*)option_records[index];
4245 option.assignvalue (log_file);
4346}
0 commit comments