toolkit/source/awt/vclxmenu.cxx |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

New commits:
commit 54b80473f4a4b8ac3dfc1936b2214733474a3485
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sat Dec 18 16:16:53 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Dec 18 16:28:15 2021 +0100

    tdf#146286 Crash/hang calling context menu
    
    regression from
        commit b37f9fbf05e16eb58eae40c6d900a4b9da2972db
        osl::Mutex->std::mutex in VCLXMenu
    
    Change-Id: I60caa02f9d8bb40b7fcf8a1009aeeac6ff3a094c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127044
    Tested-by: Julien Nabet <serval2...@yahoo.fr>
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/toolkit/source/awt/vclxmenu.cxx b/toolkit/source/awt/vclxmenu.cxx
index 01e275aacf82..eca9de23fa12 100644
--- a/toolkit/source/awt/vclxmenu.cxx
+++ b/toolkit/source/awt/vclxmenu.cxx
@@ -479,16 +479,17 @@ sal_Int16 VCLXMenu::execute(
     sal_Int16 nFlags )
 {
     SolarMutexGuard aSolarGuard;
-    std::unique_lock aGuard( maMutex );
-
-    sal_Int16 nRet = 0;
-    if ( mpMenu && IsPopupMenu() )
+    auto pMenu = mpMenu;
     {
-        nRet = static_cast<PopupMenu*>(mpMenu.get())->Execute( 
VCLUnoHelper::GetWindow( rxWindowPeer ),
-                                              VCLRectangle( rPos ),
-                                              
static_cast<PopupMenuFlags>(nFlags) | PopupMenuFlags::NoMouseUpClose );
+        std::unique_lock aGuard( maMutex );
+        if ( !mpMenu || !IsPopupMenu() )
+            return 0;
     }
-    return nRet;
+    // cannot call this with mutex locked because it will call back into us
+    return static_cast<PopupMenu*>(pMenu.get())->Execute(
+                VCLUnoHelper::GetWindow( rxWindowPeer ),
+                VCLRectangle( rPos ),
+                static_cast<PopupMenuFlags>(nFlags) | 
PopupMenuFlags::NoMouseUpClose );
 }
 
 

Reply via email to