[Libreoffice-commits] core.git: compilerplugins/clang sdext/source sw/inc sw/source vcl/source

Noel Grandin noel at peralex.com
Mon Apr 18 10:52:16 UTC 2016


 compilerplugins/clang/badstatics.cxx       |    8 ++------
 sdext/source/pdfimport/wrapper/wrapper.cxx |   11 ++++++-----
 sw/inc/viewsh.hxx                          |    5 +++--
 sw/source/core/inc/fntcache.hxx            |    1 -
 sw/source/core/txtnode/fntcache.cxx        |    7 ++++---
 sw/source/core/view/viewsh.cxx             |    4 ++--
 vcl/source/window/winproc.cxx              |   12 +++++++-----
 7 files changed, 24 insertions(+), 24 deletions(-)

New commits:
commit 67d333c608a662621c1069aacdec75e45e33a183
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Apr 18 11:21:44 2016 +0200

    tdf#99352 - Some VclPtrs leak past DeInitVCL
    
    Change-Id: I74b27b1d8b662a644df580ae128643b8495355f8
    Reviewed-on: https://gerrit.libreoffice.org/24204
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx
index ecc9300..d3fc831 100644
--- a/compilerplugins/clang/badstatics.cxx
+++ b/compilerplugins/clang/badstatics.cxx
@@ -146,13 +146,9 @@ public:
             {
                 return true;
             }
-            // TODO: check these VclPtr<> static fields
-            if (   name == "xPreviousWindow"    // vcl/source/window/winproc.cxx
-                || name == "vDev"               // sdext/source/pdfimport/wrapper/wrapper.cxx
-                || name == "s_xEmptyController" // svx/source/fmcomp/gridcell.cxx
+            // these two are fairly harmless because they're both empty objects
+            if (   name == "s_xEmptyController" // svx/source/fmcomp/gridcell.cxx
                 || name == "xCell"              // svx/source/table/svdotable.cxx
-                || name == "pPixOut"            // sw/source/core/txtnode/fntcache.cxx
-                || name == "mpCareWindow"       // sw/source/core/view/viewsh.cxx
                )
             {
                 return true;
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index 06a9763..48e3924 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -59,6 +59,7 @@
 #include <vcl/metric.hxx>
 #include <vcl/font.hxx>
 #include <vcl/virdev.hxx>
+#include <vcl/lazydelete.hxx>
 
 #include <memory>
 #include <unordered_map>
@@ -662,13 +663,13 @@ void Parser::readFont()
 
     }
 
-    static VclPtr<VirtualDevice> vDev;
-    if (!vDev)
-        vDev = VclPtr<VirtualDevice>::Create();
+    static vcl::DeleteOnDeinit< VclPtr<VirtualDevice> > vDev( new VclPtr<VirtualDevice> );
+    if (!vDev.get()->get())
+        (*vDev.get()) = VclPtr<VirtualDevice>::Create();
 
     vcl::Font font(aResult.familyName, Size(0, 1000));
-    vDev->SetFont(font);
-    FontMetric metric(vDev->GetFontMetric());
+    (*vDev.get())->SetFont(font);
+    FontMetric metric((*vDev.get())->GetFontMetric());
     aResult.ascent = metric.GetAscent() / 1000.0;
 
     m_aFontMap[nFontID] = aResult;
diff --git a/sw/inc/viewsh.hxx b/sw/inc/viewsh.hxx
index e4ee7d6..3df2cd8 100644
--- a/sw/inc/viewsh.hxx
+++ b/sw/inc/viewsh.hxx
@@ -30,6 +30,7 @@
 #include <vcl/mapmod.hxx>
 #include <vcl/print.hxx>
 #include <vcl/vclptr.hxx>
+#include <vcl/lazydelete.hxx>
 
 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
 
@@ -180,7 +181,7 @@ class SW_DLLPUBLIC SwViewShell : public sw::Ring<SwViewShell>
 
 protected:
     static ShellResource*      mpShellRes;      ///< Resources for the Shell.
-    static VclPtr<vcl::Window> mpCareWindow;    ///< Avoid this window.
+    static vcl::DeleteOnDeinit< VclPtr<vcl::Window> > mpCareWindow;    ///< Avoid this window.
 
     SwRect                  maVisArea;       ///< The modern version of VisArea.
     SwDoc                   *mpDoc;          ///< The document; never 0.
@@ -436,7 +437,7 @@ public:
 
     static void           SetCareWin( vcl::Window* pNew );
     static vcl::Window*   GetCareWin(SwViewShell& rVSh)
-                          { return mpCareWindow ? mpCareWindow.get() : CareChildWin(rVSh); }
+                          { return (*mpCareWindow.get()) ? mpCareWindow.get()->get() : CareChildWin(rVSh); }
     static vcl::Window*   CareChildWin(SwViewShell& rVSh);
 
     inline SfxViewShell   *GetSfxViewShell() const { return mpSfxViewShell; }
diff --git a/sw/source/core/inc/fntcache.hxx b/sw/source/core/inc/fntcache.hxx
index 7d5dc0a..b0117a0 100644
--- a/sw/source/core/inc/fntcache.hxx
+++ b/sw/source/core/inc/fntcache.hxx
@@ -78,7 +78,6 @@ class SwFntObj : public SwCacheObj
 
     static long nPixWidth;
     static MapMode *pPixMap;
-    static VclPtr<OutputDevice> pPixOut;
 
 public:
     DECL_FIXEDMEMPOOL_NEWDEL(SwFntObj)
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index b612985..989d6d6 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -28,6 +28,7 @@
 #include <vcl/metric.hxx>
 #include <vcl/window.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/lazydelete.hxx>
 #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
 #include <com/sun/star/i18n/WordType.hpp>
 #include <breakit.hxx>
@@ -68,7 +69,7 @@ Color *pWaveCol = nullptr;
 
 long SwFntObj::nPixWidth;
 MapMode* SwFntObj::pPixMap = nullptr;
-VclPtr<OutputDevice> SwFntObj::pPixOut;
+static vcl::DeleteOnDeinit< VclPtr<OutputDevice> > s_pFntObjPixOut( new VclPtr<OutputDevice> );
 
 namespace
 {
@@ -889,10 +890,10 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
     Point aTextOriginPos( rInf.GetPos() );
     if( !bPrt )
     {
-        if( rInf.GetpOut() != pPixOut || rInf.GetOut().GetMapMode() != *pPixMap )
+        if( rInf.GetpOut() != *s_pFntObjPixOut.get() || rInf.GetOut().GetMapMode() != *pPixMap )
         {
             *pPixMap = rInf.GetOut().GetMapMode();
-            pPixOut = rInf.GetpOut();
+            (*s_pFntObjPixOut.get()) = rInf.GetpOut();
             Size aTmp( 1, 1 );
             nPixWidth = rInf.GetOut().PixelToLogic( aTmp ).Width();
         }
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index bf41526..769cd93 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -88,7 +88,7 @@
 
 bool SwViewShell::mbLstAct = false;
 ShellResource *SwViewShell::mpShellRes = nullptr;
-VclPtr<vcl::Window> SwViewShell::mpCareWindow = nullptr;
+vcl::DeleteOnDeinit< VclPtr<vcl::Window> > SwViewShell::mpCareWindow(new VclPtr<vcl::Window>);
 
 bool bInSizeNotify = false;
 
@@ -2418,7 +2418,7 @@ ShellResource* SwViewShell::GetShellRes()
 
 void SwViewShell::SetCareWin( vcl::Window* pNew )
 {
-    mpCareWindow = pNew;
+    (*mpCareWindow.get()) = pNew;
 }
 
 sal_uInt16 SwViewShell::GetPageCount() const
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index 062136e..fe5286d 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -36,6 +36,7 @@
 #include <vcl/dockwin.hxx>
 #include <vcl/menu.hxx>
 #include <vcl/virdev.hxx>
+#include <vcl/lazydelete.hxx>
 #include <touch/touch.h>
 
 #include <svdata.hxx>
@@ -1473,7 +1474,7 @@ public:
 bool HandleWheelEvent::HandleEvent(const SalWheelMouseEvent& rEvt)
 {
     static SalWheelMouseEvent aPreviousEvent;
-    static VclPtr<vcl::Window> xPreviousWindow;
+    static vcl::DeleteOnDeinit< VclPtr<vcl::Window> > xPreviousWindow( new VclPtr<vcl::Window> );
 
     if (!Setup())
         return false;
@@ -1483,16 +1484,17 @@ bool HandleWheelEvent::HandleEvent(const SalWheelMouseEvent& rEvt)
     // avoid the problem that scrolling via wheel to this point brings a widget
     // under the mouse that also accepts wheel commands, so stick with the old
     // widget if the time gap is very small
-    if (shouldReusePreviousMouseWindow(aPreviousEvent, rEvt) && acceptableWheelScrollTarget(xPreviousWindow))
+    VclPtr<vcl::Window> tmp = *xPreviousWindow.get();
+    if (shouldReusePreviousMouseWindow(aPreviousEvent, rEvt) && acceptableWheelScrollTarget(tmp))
     {
-        xMouseWindow = xPreviousWindow.get();
+        xMouseWindow = tmp;
     }
 
     aPreviousEvent = rEvt;
 
-    xPreviousWindow = Dispatch(xMouseWindow);
+    (*xPreviousWindow.get()) = Dispatch(xMouseWindow);
 
-    return xPreviousWindow;
+    return *xPreviousWindow.get();
 }
 
 class HandleGestureEvent : public HandleGestureEventBase


More information about the Libreoffice-commits mailing list