From a79cb95c85237adb5ab210e6949776ac00cabdfb Mon Sep 17 00:00:00 2001 From: seelabs Date: Tue, 18 Jul 2017 16:25:18 -0400 Subject: [PATCH] Fix use after free error in test code --- src/test/app/ValidatorSite_test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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_,