]> git.sesse.net Git - stockfish/commitdiff
Fix a crash when quitting while searching
authorMarco Costalba <mcostalba@gmail.com>
Sun, 11 Dec 2011 09:07:16 +0000 (10:07 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 11 Dec 2011 09:31:46 +0000 (10:31 +0100)
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 <mcostalba@gmail.com>
src/position.cpp

index bed08ebad00865a1cbe4c67347552ed4872e8196..bf8497cf90f79310f2a0f5e6a1c67cecbdd18cc9 100644 (file)
@@ -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;