1
0
Fork 0

Fix a Windows-only crash on exit without 'quit'

There was a bug in commit d4763424d2
(Add support for Windows large pages) that could result in trying to
free memory allocated with VirtualAlloc incorrectly with free().

Fix this by reverting the TT.resize(0) logic in the previous commit,
and instead, just call aligned_ttmem_free() in
TranspositionTable::~TranspositionTable().

fixes https://github.com/official-stockfish/Stockfish/issues/2677

closes https://github.com/official-stockfish/Stockfish/pull/2679

No functional change
pull/2682/head
Sami Kiminki 2020-05-14 12:00:35 +03:00 committed by Joost VandeVondele
parent cca643669d
commit beb327f910
5 changed files with 4 additions and 12 deletions

View File

@ -49,7 +49,6 @@ int main(int argc, char* argv[]) {
UCI::loop(argc, argv);
TT.resize(0);
Threads.set(0);
return 0;
}

View File

@ -390,7 +390,7 @@ void* aligned_ttmem_alloc(size_t allocSize, void*& mem) {
void aligned_ttmem_free(void* mem) {
if (!VirtualFree(mem, 0, MEM_RELEASE))
if (mem && !VirtualFree(mem, 0, MEM_RELEASE))
{
DWORD err = GetLastError();
std::cerr << "Failed to free transposition table. Error code: 0x" <<

View File

@ -34,7 +34,7 @@ const std::string compiler_info();
void prefetch(void* addr);
void start_logger(const std::string& fname);
void* aligned_ttmem_alloc(size_t size, void*& mem);
void aligned_ttmem_free(void* mem);
void aligned_ttmem_free(void* mem); // nop if mem == nullptr
void dbg_hit_on(bool b);
void dbg_hit_on(bool c, bool b);

View File

@ -63,14 +63,7 @@ void TranspositionTable::resize(size_t mbSize) {
Threads.main()->wait_for_search_finished();
if (mem)
aligned_ttmem_free(mem);
if (!mbSize)
{
mem = nullptr;
return;
}
aligned_ttmem_free(mem);
clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
table = static_cast<Cluster*>(aligned_ttmem_alloc(clusterCount * sizeof(Cluster), mem));

View File

@ -75,7 +75,7 @@ class TranspositionTable {
static_assert(sizeof(Cluster) == 32, "Unexpected Cluster size");
public:
~TranspositionTable() { free(mem); }
~TranspositionTable() { aligned_ttmem_free(mem); }
void new_search() { generation8 += 8; } // Lower 3 bits are used by PV flag and Bound
TTEntry* probe(const Key key, bool& found) const;
int hashfull() const;