From: Marco Costalba Date: Sun, 11 Dec 2011 09:07:16 +0000 (+0100) Subject: Fix a crash when quitting while searching X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=377c406c748643d1aeec6a7ce9a45b32a7416bf3;hp=91601d7f95a3e84d2d46ca9a36637508197dbdab Fix a crash when quitting while searching The Position object used by UI thread is a local variable in uci_loop(), so after receiving "quit" command the function returns and the position is freed from the stack. This should not be a problem becuase in start_thinking() we copy the position to RootPosition that is the one used by main search thread. Unfortunatly we blindly copy also StateInfo pointer that still points to the startState struct inside UI position. So the pointer becomes stale as soon as UI thread leaves uci_loop() and because this happens while main search thread is still recovering after the 'stop' signal we have a crash. The fix is to update the pointer to the correct startState after the copy. Found with Valgrind. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/position.cpp b/src/position.cpp index bed08eba..bf8497cf 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -100,6 +100,7 @@ CheckInfo::CheckInfo(const Position& pos) { void Position::copy(const Position& pos, int th) { memcpy(this, &pos, sizeof(Position)); + st = &startState; threadID = th; nodes = 0;