Skip to content

Commit

Permalink
fix multiple call to fclose
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Oct 16, 2023
1 parent ad2ecf4 commit e6cfce1
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,24 @@
class SolverLogManager {
public:
explicit SolverLogManager() = default;
explicit SolverLogManager(const SolverLogManager &other)
: SolverLogManager(other.log_file_path) {}

explicit SolverLogManager(const std::filesystem::path &log_file)
: log_file_path(log_file) {
init();
}

SolverLogManager &operator=(const SolverLogManager &other) {
if (this == &other) {
return *this;
}
log_file_path = other.log_file_path;
init();
return *this;
}

void init() {
#ifdef __linux__
if (log_file_path.empty() ||
(log_file_ptr = fopen(log_file_path.string().c_str(), "a+")) == nullptr)
Expand All @@ -28,19 +44,18 @@ class SolverLogManager {
#endif
{
std::cout << "Invalid log file name passed as parameter: "
<< std::quoted(log_file.string()) << std::endl;
<< std::quoted(log_file_path.string()) << std::endl;
} else {
setvbuf(log_file_ptr, nullptr, _IONBF, 0);
}
}
//TODO
/* ~SolverLogManager() {
~SolverLogManager() {
if (log_file_ptr) {
fclose(log_file_ptr);
log_file_ptr = nullptr;
}
}
*/

FILE *log_file_ptr = nullptr;
std::filesystem::path log_file_path = "";
};
Expand Down

0 comments on commit e6cfce1

Please sign in to comment.