From 9d450881275b3f02ee4734392db2e184aaefce95 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 14 Aug 2017 22:27:28 -0700 Subject: [PATCH] Fix destruction order issue in SourceImpl. (#89) The Frame destructor calls back into SourceImpl, locking m_poolMutex, so it's necessary to destroy m_frame before m_poolMutex. Reverse destruction order to member definition order is guaranteed by the C++ standard. --- src/SourceImpl.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/SourceImpl.h b/src/SourceImpl.h index f023d89e2b..06809135a7 100644 --- a/src/SourceImpl.h +++ b/src/SourceImpl.h @@ -202,10 +202,6 @@ class SourceImpl { std::mutex m_frameMutex; std::condition_variable m_frameCv; - // Most recent frame (returned to callers of GetNextFrame) - // Access protected by m_frameMutex. - Frame m_frame; - bool m_destroyFrames{false}; // Pool of frames/images to reduce malloc traffic. @@ -214,6 +210,12 @@ class SourceImpl { std::vector> m_imagesAvail; std::atomic_bool m_connected{false}; + + // Most recent frame (returned to callers of GetNextFrame) + // Access protected by m_frameMutex. + // MUST be located below m_poolMutex as the Frame destructor calls back + // into SourceImpl::ReleaseImage, which locks m_poolMutex. + Frame m_frame; }; } // namespace cs