sfx2/source/view/lokhelper.cxx |   13 ++++++++-----
 vcl/source/window/window2.cxx  |    6 +++---
 2 files changed, 11 insertions(+), 8 deletions(-)

New commits:
commit f64fd5abf2a9cd7dd2cba9a57a4c8013cd634472
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Mon Jan 3 14:15:49 2022 +0000
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Tue Jan 4 14:39:14 2022 +0100

    lokit: double check for disposed windows & fix leak.
    
    it seems we can get windows disposed before we get to the emission.
    
    <segv>
    vcl::Window::IsTracking() const vcl/source/window/window2.cxx:341
    (anonymous namespace)::LOKPostAsyncEvent(void*, void*) 
sfx2/source/view/lokhelper.cxx:725
    LokChartHelper::postMouseEvent(int, int, int, int, int, int, double, 
double) include/rtl/ref.hxx:112
    SwXTextDocument::postMouseEvent(int, int, int, int, int, int) 
sw/source/uibase/uno/unotxdoc.cxx:3561
    
    Change-Id: I93aea931dad1e7f43d3d610568424c53d2b22fbc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127898
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index d8766225fcbe..a8dc5b5bf3b7 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -673,7 +673,7 @@ namespace
 
     void LOKPostAsyncEvent(void* pEv, void*)
     {
-        LOKAsyncEventData* pLOKEv = static_cast<LOKAsyncEventData*>(pEv);
+        std::unique_ptr<LOKAsyncEventData> 
pLOKEv(static_cast<LOKAsyncEventData*>(pEv));
         if (pLOKEv->mpWindow->IsDisposed())
             return;
 
@@ -694,6 +694,9 @@ namespace
         if (!pFocusWindow)
             pFocusWindow = pLOKEv->mpWindow;
 
+        if (pLOKEv->mpWindow->IsDisposed())
+            return;
+
         switch (pLOKEv->mnEvent)
         {
         case VclEventId::WindowKeyInput:
@@ -702,11 +705,13 @@ namespace
             KeyEvent singlePress(pLOKEv->maKeyEvent.GetCharCode(),
                                  pLOKEv->maKeyEvent.GetKeyCode());
             for (sal_uInt16 i = 0; i <= nRepeat; ++i)
-                pFocusWindow->KeyInput(singlePress);
+                if (!pFocusWindow->IsDisposed())
+                    pFocusWindow->KeyInput(singlePress);
             break;
         }
         case VclEventId::WindowKeyUp:
-            pFocusWindow->KeyUp(pLOKEv->maKeyEvent);
+            if (!pFocusWindow->IsDisposed())
+                pFocusWindow->KeyUp(pLOKEv->maKeyEvent);
             break;
         case VclEventId::WindowMouseButtonDown:
             pLOKEv->mpWindow->LogicMouseButtonDown(pLOKEv->maMouseEvent);
@@ -737,8 +742,6 @@ namespace
             assert(false);
             break;
         }
-
-        delete pLOKEv;
     }
 
     void postEventAsync(LOKAsyncEventData *pEvent)
diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx
index 8b2e145d0aae..811371b2396f 100644
--- a/vcl/source/window/window2.cxx
+++ b/vcl/source/window/window2.cxx
@@ -338,9 +338,9 @@ void Window::EndTracking( TrackingEventFlags nFlags )
 
 bool Window::IsTracking() const
 {
-    return (mpWindowImpl->mbUseFrameData ?
-            mpWindowImpl->mpFrameData->mpTrackWin == this :
-            ImplGetSVData()->mpWinData->mpTrackWin == this);
+    return mpWindowImpl && (mpWindowImpl->mbUseFrameData ?
+                            mpWindowImpl->mpFrameData->mpTrackWin == this :
+                            ImplGetSVData()->mpWinData->mpTrackWin == this);
 }
 
 void Window::StartAutoScroll( StartAutoScrollFlags nFlags )

Reply via email to