X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbook.cpp;h=c69eab739b7dfcae8284db5c417225ad466a831a;hp=8e4778eed711813b5ad6c3a46ff77b783aa859c9;hb=2155fb78256204aae5aa80946dfe7d8d9c6e2397;hpb=a03b8074c884086d13b80e1d291b3800a4512a3c;ds=sidebyside diff --git a/src/book.cpp b/src/book.cpp index 8e4778ee..c69eab73 100644 --- a/src/book.cpp +++ b/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); } }