[vlc-commits] qt: medialib: fix race condition

Romain Vimont git at videolan.org
Thu Nov 12 15:48:10 CET 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Mon Nov  9 17:33:57 2020 +0100| [bf3397c83eb35071e4169679f3e6fddf4e2cfb6a] | committer: Alexandre Janniaux

qt: medialib: fix race condition

If cancel() was called before the first lock was acquired in run(), then
cancel() would return immediately and run() would continue as if it was
not canceled (which could cause segfaults).

To avoid the problem, always set the "canceled" flag on cancel, so that
any future execution of run() will return immediately.

Note: we could alternatively track the "finished" state, and wait until
the task is finished on cancel(). However, if run() may not start
immediately (if the thread pool is full), this strategy would cause to
block on cancel() until run() is actually executed, which is
unnecessary.

Signed-off-by: Alexandre Janniaux <ajanni at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bf3397c83eb35071e4169679f3e6fddf4e2cfb6a
---

 modules/gui/qt/medialibrary/mlgenre.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/gui/qt/medialibrary/mlgenre.cpp b/modules/gui/qt/medialibrary/mlgenre.cpp
index a1067d52be..d2f13f37f7 100644
--- a/modules/gui/qt/medialibrary/mlgenre.cpp
+++ b/modules/gui/qt/medialibrary/mlgenre.cpp
@@ -185,9 +185,9 @@ public:
     void cancel()
     {
         QMutexLocker lock(&m_taskLock);
+        m_canceled = true;
         if (!m_running)
             return;
-        m_canceled = true;
         m_taskCond.wait(&m_taskLock);
     }
 



More information about the vlc-commits mailing list