[libcamera-devel,4/7] libcamera: camera_manager: Protect cameras_ by mutex in cleanup()
diff mbox series

Message ID 20211203164619.1541033-5-hiroh@chromium.org
State New
Headers show
Series
  • Apply clang thread safety annotation libcamera-core and v4l2
Related show

Commit Message

Hirokazu Honda Dec. 3, 2021, 4:46 p.m. UTC
This fixes the bug that camera_ is accessed without acquiring
mutex_ in CameraManager::Private::cleanup().

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/libcamera/camera_manager.cpp | 3 +++
 1 file changed, 3 insertions(+)

Patch
diff mbox series

diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index 70d73822..4492edc3 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -178,7 +178,10 @@  void CameraManager::Private::cleanup()
 	 * process deletion requests from the thread's message queue as the event
 	 * loop is not in action here.
 	 */
+	mutex_.lock();
 	cameras_.clear();
+	mutex_.unlock();
+
 	dispatchMessages(Message::Type::DeferredDelete);
 
 	enumerator_.reset(nullptr);