mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 09:06:45 +08:00
Be sure book file is closed before we leave
Move closing of file in Book destructor. This guarantees us against leaving the file open under any case and simplifies also Book use. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
13
src/book.cpp
13
src/book.cpp
@@ -344,10 +344,21 @@ namespace {
|
||||
////
|
||||
|
||||
|
||||
/// Destructor. Be sure file is closed before we leave.
|
||||
|
||||
Book::~Book() {
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
/// Book::open() opens a book file with a given file name
|
||||
|
||||
void Book::open(const string& fName) {
|
||||
|
||||
// Close old file before opening the new
|
||||
close();
|
||||
|
||||
fileName = fName;
|
||||
ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary);
|
||||
if (!is_open())
|
||||
@@ -361,7 +372,6 @@ void Book::open(const string& fName) {
|
||||
if (!good())
|
||||
{
|
||||
cerr << "Failed to open book file " << fileName << endl;
|
||||
close();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -479,7 +489,6 @@ void Book::read_entry(BookEntry& entry, int idx) {
|
||||
if (!good())
|
||||
{
|
||||
cerr << "Failed to read book entry at index " << idx << endl;
|
||||
close();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user