[vlc-devel] [PATCH] qt: fix lock-order-inversion when closing the thread

Thomas Guillem thomas at gllm.fr
Tue May 7 16:53:20 CEST 2019


p_sys->p_mi doesn't need to be protected here since only this thread can write
on it.

WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=22394)
  Cycle in lock order graph: M135 (0x7b5000000018) => M100 (0x7b2400000490) => M281 (0x7fcfa83b2680) => M135

  Mutex M100 acquired here while holding mutex M135 in main thread:
    #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3799 (libtsan.so.0+0x3d62b)
    #1 vlc_mutex_lock ../../src/posix/thread.c:142 (libvlccore.so.9+0xf3d6b)
    #2 input_resource_SetInput ../../src/input/resource.c:361 (libvlccore.so.9+0x98726)
    #3 Create ../../src/input/input.c:416 (libvlccore.so.9+0x835d9)
    #4 input_Create ../../src/input/input.c:137 (libvlccore.so.9+0x83ce9)
    #5 vlc_player_input_New ../../src/input/player.c:671 (libvlccore.so.9+0x8c48a)
    #6 vlc_player_OpenNextMedia ../../src/input/player.c:751 (libvlccore.so.9+0x8c65f)
    #7 vlc_player_SetCurrentMedia ../../src/input/player.c:2102 (libvlccore.so.9+0x9066a)
    #8 vlc_playlist_SetCurrentMedia ../../src/playlist/control.c:159 (libvlccore.so.9+0x52ea8)
    #9 vlc_playlist_GoTo ../../src/playlist/control.c:410 (libvlccore.so.9+0x5395d)
    #10 libvlc_InternalPlay ../../src/interface/interface.c:268 (libvlccore.so.9+0x4522d)
    #11 libvlc_playlist_play ../../lib/playlist.c:38 (libvlc.so.12+0xab18)
    #12 main ../../bin/vlc.c:248 (vlc-static+0x2793)

  Mutex M135 previously acquired by the same thread here:
    #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3799 (libtsan.so.0+0x3d62b)
    #1 vlc_mutex_lock ../../src/posix/thread.c:142 (libvlccore.so.9+0xf3d6b)
    #2 vlc_player_Lock ../../src/input/player.c:2016 (libvlccore.so.9+0x8fd52)
    #3 vlc_playlist_Lock ../../src/playlist/playlist.c:82 (libvlccore.so.9+0x54d20)
    #4 libvlc_InternalPlay ../../src/interface/interface.c:264 (libvlccore.so.9+0x451ed)
    #5 libvlc_playlist_play ../../lib/playlist.c:38 (libvlc.so.12+0xab18)
    #6 main ../../bin/vlc.c:248 (vlc-static+0x2793)

  Mutex M281 acquired here while holding mutex M100 in thread T21:
    #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3799 (libtsan.so.0+0x3d62b)
    #1 vlc_mutex_lock ../../src/posix/thread.c:142 (libvlccore.so.9+0xf3d6b)
    #2 vlc_mutex_locker::vlc_mutex_locker(pthread_mutex_t*) ../../include/vlc_threads.h:1125 (libqt_plugin.so+0x82468)
    #3 WindowOpen ../../modules/gui/qt/qt.cpp:829 (libqt_plugin.so+0x82468)
    #4 vout_window_start ../../src/video_output/window.c:55 (libvlccore.so.9+0xbdc0b)
    #5 module_load ../../src/modules/modules.c:122 (libvlccore.so.9+0x3cd95)
    #6 vlc_module_load ../../src/modules/modules.c:194 (libvlccore.so.9+0x3d26f)
    #7 vout_window_New ../../src/video_output/window.c:82 (libvlccore.so.9+0xbe3df)
    #8 vout_display_window_New ../../src/video_output/window.c:364 (libvlccore.so.9+0xbe868)
    #9 vout_Create ../../src/video_output/video_output.c:1785 (libvlccore.so.9+0xb4bf1)
    #10 input_resource_GetVout ../../src/input/resource.c:389 (libvlccore.so.9+0x98bbb)
    #11 vout_update_format ../../src/input/decoder.c:537 (libvlccore.so.9+0x68507)
    #12 decoder_UpdateVideoFormat ../../src/input/decoder_helpers.c:84 (libvlccore.so.9+0x6c3b1)
    #13 <null> <null> (libavcodec_plugin.so+0x4a91)
    #14 <null> <null> (libavcodec_plugin.so+0x6dd5)
    #15 <null> <null> (libavcodec.so.58+0x2424d1)

  Mutex M100 previously acquired by the same thread here:
    #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3799 (libtsan.so.0+0x3d62b)
    #1 vlc_mutex_lock ../../src/posix/thread.c:142 (libvlccore.so.9+0xf3d6b)
    #2 input_resource_GetVout ../../src/input/resource.c:380 (libvlccore.so.9+0x98a15)
    #3 vout_update_format ../../src/input/decoder.c:537 (libvlccore.so.9+0x68507)
    #4 decoder_UpdateVideoFormat ../../src/input/decoder_helpers.c:84 (libvlccore.so.9+0x6c3b1)
    #5 <null> <null> (libavcodec_plugin.so+0x4a91)
    #6 <null> <null> (libavcodec_plugin.so+0x6dd5)
    #7 <null> <null> (libavcodec.so.58+0x2424d1)

  Mutex M135 acquired here while holding mutex M281 in thread T6:
    #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3799 (libtsan.so.0+0x3d62b)
    #1 vlc_mutex_lock ../../src/posix/thread.c:142 (libvlccore.so.9+0xf3d6b)
    #2 vlc_player_Lock ../../src/input/player.c:2016 (libvlccore.so.9+0x8fd52)
    #3 vlc_playlist_Lock ../../src/playlist/playlist.c:82 (libvlccore.so.9+0x54d20)
    #4 PlaylistLocker::PlaylistLocker(vlc_playlist*) ../../modules/gui/qt/components/playlist/playlist_common.hpp:47 (libqt_plugin.so+0x231cea)
    #5 vlc::playlist::PlaylistControllerModelPrivate::~PlaylistControllerModelPrivate() ../../modules/gui/qt/components/playlist/playlist_controller.cpp:285 (libqt_plugin.so+0x231cea)
    #6 QScopedPointerDeleter<vlc::playlist::PlaylistControllerModelPrivate>::cleanup(vlc::playlist::PlaylistControllerModelPrivate*) /usr/include/x86_64-linux-gnu/qt5/QtCore/qscopedpointer.h:60 (libqt_plugin.so+0x231ff8)
    #7 QScopedPointer<vlc::playlist::PlaylistControllerModelPrivate, QScopedPointerDeleter<vlc::playlist::PlaylistControllerModelPrivate> >::~QScopedPointer() /usr/include/x86_64-linux-gnu/qt5/QtCore/qscopedpointer.h:107 (libqt_plugin.so+0x231ff8)
    #8 vlc::playlist::PlaylistControllerModel::~PlaylistControllerModel() ../../modules/gui/qt/components/playlist/playlist_controller.cpp:305 (libqt_plugin.so+0x231ff8)
    #9 <null> <null> (libqt_plugin.so+0xa07ae)
    #10 QObjectPrivate::deleteChildren() <null> (libQt5Core.so.5+0x29186a)
    #11 MainInterface::~MainInterface() ../../modules/gui/qt/main_interface.cpp:274 (libqt_plugin.so+0x9a491)
    #12 ThreadCleanup ../../modules/gui/qt/qt.cpp:757 (libqt_plugin.so+0x8261e)
    #13 Thread ../../modules/gui/qt/qt.cpp:734 (libqt_plugin.so+0x85b21)

  Mutex M281 previously acquired by the same thread here:
    #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3799 (libtsan.so.0+0x3d62b)
    #1 vlc_mutex_lock ../../src/posix/thread.c:142 (libvlccore.so.9+0xf3d6b)
    #2 vlc_mutex_locker::vlc_mutex_locker(pthread_mutex_t*) ../../include/vlc_threads.h:1125 (libqt_plugin.so+0x825c0)
    #3 ThreadCleanup ../../modules/gui/qt/qt.cpp:742 (libqt_plugin.so+0x825c0)
    #4 Thread ../../modules/gui/qt/qt.cpp:734 (libqt_plugin.so+0x85b21)

  Thread T21 (tid=22421, finished) created by thread T20 at:
    #0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors.cc:915 (libtsan.so.0+0x2be1b)
    #1 <null> <null> (libavcodec.so.58+0x5e4f3d)
    #2 <null> <null> (libavcodec_plugin.so+0x55e6)
    #3 <null> <null> (libavcodec_plugin.so+0x91da)
    #4 generic_start ../../src/modules/modules.c:258 (libvlccore.so.9+0x3cdec)
    #5 module_load ../../src/modules/modules.c:122 (libvlccore.so.9+0x3cd95)
    #6 vlc_module_load ../../src/modules/modules.c:194 (libvlccore.so.9+0x3d26f)
    #7 module_need ../../src/modules/modules.c:277 (libvlccore.so.9+0x3d523)
    #8 module_need_var ../../include/vlc_modules.h:98 (libvlccore.so.9+0x68cca)
    #9 LoadDecoder ../../src/input/decoder.c:180 (libvlccore.so.9+0x68cca)
    #10 CreateDecoder ../../src/input/decoder.c:1871 (libvlccore.so.9+0x6a002)
    #11 decoder_New ../../src/input/decoder.c:2028 (libvlccore.so.9+0x6a306)
    #12 input_DecoderNew ../../src/input/decoder.c:2091 (libvlccore.so.9+0x6ad82)
    #13 EsOutCreateDecoder ../../src/input/es_out.c:1824 (libvlccore.so.9+0x70785)
    #14 EsOutSelectEs ../../src/input/es_out.c:1937 (libvlccore.so.9+0x70c21)
    #15 EsOutSelect ../../src/input/es_out.c:2169 (libvlccore.so.9+0x71c45)
    #16 EsOutVaControlLocked ../../src/input/es_out.c:2528 (libvlccore.so.9+0x782b9)
    #17 EsOutControl ../../src/input/es_out.c:3196 (libvlccore.so.9+0x7a3a8)
    #18 es_out_vaControl ../../include/vlc_es_out.h:158 (libvlccore.so.9+0x7c624)
    #19 es_out_Control ../../include/vlc_es_out.h:167 (libvlccore.so.9+0x7c624)
    #20 CmdExecuteControl ../../src/input/es_out_timeshift.c:1556 (libvlccore.so.9+0x7c912)
    #21 ControlLocked ../../src/input/es_out_timeshift.c:638 (libvlccore.so.9+0x7e3aa)
    #22 Control ../../src/input/es_out_timeshift.c:764 (libvlccore.so.9+0x7e7c6)
    #23 es_out_vaControl ../../include/vlc_es_out.h:158 (libvlccore.so.9+0x7ffb5)
    #24 es_out_Control ../../include/vlc_es_out.h:167 (libvlccore.so.9+0x7ffb5)
    #25 es_out_SetMode ../../src/input/es_out.h:97 (libvlccore.so.9+0x82de7)
    #26 InitPrograms ../../src/input/input.c:1335 (libvlccore.so.9+0x82de7)
    #27 Init ../../src/input/input.c:1416 (libvlccore.so.9+0x88def)
    #28 Run ../../src/input/input.c:563 (libvlccore.so.9+0x89cd4)

  Thread T6 (tid=22402, running) created by main thread at:
    #0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors.cc:915 (libtsan.so.0+0x2be1b)
    #1 vlc_clone_attr ../../src/posix/thread.c:421 (libvlccore.so.9+0xf35db)
    #2 vlc_clone ../../src/posix/thread.c:433 (libvlccore.so.9+0xf3a3c)
    #3 Open ../../modules/gui/qt/qt.cpp:461 (libqt_plugin.so+0x82233)
    #4 OpenIntf ../../modules/gui/qt/qt.cpp:490 (libqt_plugin.so+0x8236d)
    #5 generic_start ../../src/modules/modules.c:258 (libvlccore.so.9+0x3cdec)
    #6 module_load ../../src/modules/modules.c:122 (libvlccore.so.9+0x3cd95)
    #7 vlc_module_load ../../src/modules/modules.c:194 (libvlccore.so.9+0x3d26f)
    #8 module_need ../../src/modules/modules.c:277 (libvlccore.so.9+0x3d523)
    #9 intf_Create ../../src/interface/interface.c:203 (libvlccore.so.9+0x44eab)
    #10 libvlc_InternalAddIntf ../../src/interface/interface.c:294 (libvlccore.so.9+0x452c0)
    #11 libvlc_add_intf ../../lib/playlist.c:43 (libvlc.so.12+0xab48)
    #12 main ../../bin/vlc.c:242 (vlc-static+0x2780)

SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) ../../src/posix/thread.c:142 in vlc_mutex_lock
---
 modules/gui/qt/qt.cpp | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index 9bffe49e0f..2998c99c5a 100644
--- a/modules/gui/qt/qt.cpp
+++ b/modules/gui/qt/qt.cpp
@@ -749,15 +749,15 @@ static void *ThreadCleanup( intf_thread_t *p_intf, bool error )
         }
         else
             open_state = OPEN_STATE_INIT;
+    }
 
-        if( p_sys->p_mi != NULL)
-        {
-            MainInterface *p_mi = p_sys->p_mi;
-            p_sys->p_mi = NULL;
-            /* Destroy first the main interface because it is connected to some
-               slots in the MainInputManager */
-            delete p_mi;
-        }
+    if( p_sys->p_mi != NULL)
+    {
+        MainInterface *p_mi = p_sys->p_mi;
+        p_sys->p_mi = NULL;
+        /* Destroy first the main interface because it is connected to some
+           slots in the MainInputManager */
+        delete p_mi;
     }
 
     /* */
-- 
2.20.1



More information about the vlc-devel mailing list