From f0a7d1faaae4e100cba45a6c8c0787f18feabe47 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 19 Apr 2022 17:09:49 -0300 Subject: [PATCH] Fix data race loading next thumbnail without locking the item This was detected with -fsanitize=thread --- src/app/thumbnail_generator.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/thumbnail_generator.cpp b/src/app/thumbnail_generator.cpp index d4677d59a..ded732746 100644 --- a/src/app/thumbnail_generator.cpp +++ b/src/app/thumbnail_generator.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -199,8 +199,14 @@ private: void loadBgThread() { while (!m_queue.empty()) { - while (m_queue.try_pop(m_item)) { - loadItem(); + bool success = true; + while (success) { + { + base::scoped_lock lock(m_mutex); // To access m_item + success = m_queue.try_pop(m_item); + } + if (success) + loadItem(); } base::this_thread::yield(); }