From d148f62e00612fdd9aa44aa1d891b03e131918c8 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Wed, 28 Jan 2015 13:48:36 -0500 Subject: [PATCH] Acquire CCheckQueue's lock to avoid race condition This fixes a potential race condition in the CCheckQueueControl constructor, which was looking directly at data in CCheckQueue without acquiring its lock. Remove the now-unnecessary friendship for CCheckQueueControl Rebased-From: cf008ac8c3c5d582562d88ad89020daef3e64dcb Github-Pull: #5721 --- src/checkqueue.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/checkqueue.h b/src/checkqueue.h index 2ee46a1210..b27f9e3d17 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -161,7 +161,12 @@ public: { } - friend class CCheckQueueControl; + bool IsIdle() + { + boost::unique_lock lock(mutex); + return (nTotal == nIdle && nTodo == 0 && fAllOk == true); + } + }; /** @@ -180,9 +185,8 @@ public: { // passed queue is supposed to be unused, or NULL if (pqueue != NULL) { - assert(pqueue->nTotal == pqueue->nIdle); - assert(pqueue->nTodo == 0); - assert(pqueue->fAllOk == true); + bool isIdle = pqueue->IsIdle(); + assert(isIdle); } }