diff --git a/src/test/app/ValidatorSite_test.cpp b/src/test/app/ValidatorSite_test.cpp index af2ee3e81..c72e50472 100644 --- a/src/test/app/ValidatorSite_test.cpp +++ b/src/test/app/ValidatorSite_test.cpp @@ -125,10 +125,11 @@ private: void on_accept(error_code ec) { - if(! acceptor_.is_open()) - return; - if(ec) + // ec must be checked before `acceptor_` or the member variable may be + // accessed after the destructor has completed + if(ec || !acceptor_.is_open()) return; + static int id_ = 0; std::thread{lambda{++id_, *this, std::move(sock_)}}.detach(); acceptor_.async_accept(sock_,