[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sfx2/source

Caolán McNamara caolan at kemper.freedesktop.org
Thu Jun 30 04:05:04 PDT 2011


 sfx2/source/dialog/templdlg.cxx |   64 ++++++++++++++++++++++++++++++----------
 sfx2/source/inc/templdgi.hxx    |   16 +++-------
 2 files changed, 55 insertions(+), 25 deletions(-)

New commits:
commit 933f19eb99435b09b61fa2d221e955c2adb3104f
Author: David Tardon <dtardon at redhat.com>
Date:   Thu Jun 30 09:20:51 2011 +0200

    avoid overwriting stack after early return
    
    Also make the original hack less noisome.
    (cherry picked from commit 01096e7487d9e60fcd24eea8131b650588845f2b)
    
    Conflicts:
    
    	sfx2/source/dialog/templdlg.cxx
    	sfx2/source/inc/templdgi.hxx

diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx
index a0f4137..6e0ca0e 100644
--- a/sfx2/source/dialog/templdlg.cxx
+++ b/sfx2/source/dialog/templdlg.cxx
@@ -29,6 +29,9 @@
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sfx2.hxx"
 
+#include <boost/noncopyable.hpp>
+#include <boost/scoped_ptr.hpp>
+
 #include <vcl/menu.hxx>
 #include <svl/intitem.hxx>
 #include <svl/stritem.hxx>
@@ -116,6 +119,39 @@ SFX_IMPL_DOCKINGWINDOW(SfxTemplateDialogWrapper, SID_STYLE_DESIGNER)
 
 //-------------------------------------------------------------------------
 
+class SfxCommonTemplateDialog_Impl::DeletionWatcher : private boost::noncopyable
+{
+    typedef void (DeletionWatcher::* bool_type)();
+
+public:
+    explicit DeletionWatcher(SfxCommonTemplateDialog_Impl& rDialog)
+        : m_pDialog(&rDialog)
+    {
+        m_pDialog->impl_setDeletionWatcher(this);
+    }
+
+    ~DeletionWatcher()
+    {
+        if (m_pDialog)
+            m_pDialog->impl_setDeletionWatcher(0);
+    }
+
+    // Signal that the dialog was deleted
+    void signal()
+    {
+        m_pDialog = 0;
+    }
+
+    // Return true if the dialog was deleted
+    operator bool_type() const
+    {
+        return m_pDialog ? 0 : &DeletionWatcher::signal;
+    }
+
+private:
+    SfxCommonTemplateDialog_Impl* m_pDialog;
+};
+
 // Re-direct functions
 
 SfxTemplateDialog::SfxTemplateDialog
@@ -741,7 +777,7 @@ SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, Sfx
     pCurObjShell			( NULL ),
     xModuleManager          ( ::comphelper::getProcessServiceFactory()->createInstance(
                                 DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY ),
-    pbDeleted               ( NULL ),
+    m_pDeletionWatcher      ( NULL ),
 
     aFmtLb					( this, WB_BORDER | WB_TABSTOP | WB_SORT | WB_QUICK_SEARCH ),
     aFilterLb				( pW, WB_BORDER | WB_DROPDOWN | WB_TABSTOP ),
@@ -786,7 +822,7 @@ SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, Mod
     pStyleSheetPool			( NULL ),
     pTreeBox				( NULL ),
     pCurObjShell			( NULL ),
-    pbDeleted               ( NULL ),
+    m_pDeletionWatcher      ( NULL ),
 
     aFmtLb					( this, SfxResId( BT_VLIST ) ),
     aFilterLb				( pW, SfxResId( BT_FLIST ) ),
@@ -959,6 +995,11 @@ void SfxCommonTemplateDialog_Impl::ClearResource()
     DELETEZ( m_pStyleFamiliesId );
 }
 
+void SfxCommonTemplateDialog_Impl::impl_setDeletionWatcher(DeletionWatcher* pNewWatcher)
+{
+    m_pDeletionWatcher = pNewWatcher;
+}
+
 //-------------------------------------------------------------------------
 
 void SfxCommonTemplateDialog_Impl::Initialize()
@@ -997,11 +1038,8 @@ SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl()
     pStyleSheetPool = NULL;
     delete pTreeBox;
     delete pTimer;
-    if ( pbDeleted )
-    {
-        pbDeleted->bDead = true;
-        pbDeleted = NULL;
-    }
+    if ( m_pDeletionWatcher )
+        m_pDeletionWatcher->signal();
 }
 
 //-------------------------------------------------------------------------
@@ -1695,15 +1733,15 @@ sal_Bool SfxCommonTemplateDialog_Impl::Execute_Impl(
 
     pItems[ nCount++ ] = 0;
 
-    Deleted aDeleted;
-    pbDeleted = &aDeleted;
+    DeletionWatcher aDeleted(*this);
     sal_uInt16 nModi = pModifier ? *pModifier : 0;
     const SfxPoolItem* pItem = rDispatcher.Execute(
         nId, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
         pItems, nModi );
 
-    // FIXME: Dialog can be destroyed while in Execute() check stack variable for dtor flag!
-    if ( !pItem || aDeleted() )
+    // Dialog can be destroyed while in Execute() because started
+    // subdialogs are not modal to it (#i97888#).
+    if ( !pItem || aDeleted )
         return sal_False;
 
     if ( nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId )
@@ -1725,10 +1763,6 @@ sal_Bool SfxCommonTemplateDialog_Impl::Execute_Impl(
         }
     }
     
-    // Reset destroyed flag otherwise we use the pointer in the dtor
-    // where the local stack object is already destroyed. This would
-    // overwrite objects on the stack!! See #i100110
-    pbDeleted = NULL;
     return sal_True;
 }
 
diff --git a/sfx2/source/inc/templdgi.hxx b/sfx2/source/inc/templdgi.hxx
index 576e93e..aa7cb6c 100644
--- a/sfx2/source/inc/templdgi.hxx
+++ b/sfx2/source/inc/templdgi.hxx
@@ -102,18 +102,12 @@ public:
 
 // class SfxCommonTemplateDialog_Impl ------------------------------------
 
-struct Deleted
-{
-    bool bDead;
-
-    Deleted() : bDead(false) {}
-
-    inline bool operator()() { return bDead; }
-};
-
 class SfxCommonTemplateDialog_Impl : public SfxListener
 {
 private:
+    class DeletionWatcher;
+    friend class DeletionWatcher;
+
     class ISfxTemplateCommon_Impl : public ISfxTemplateCommon
     {
     private:
@@ -129,6 +123,8 @@ private:
     void	ReadResource();
     void	ClearResource();
 
+    void impl_setDeletionWatcher(DeletionWatcher* pNewWatcher);
+
 protected:
 #define MAX_FAMILIES			5
 #define COUNT_BOUND_FUNC		13
@@ -155,7 +151,7 @@ protected:
     SfxObjectShell*				pCurObjShell;
     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >
                                 xModuleManager;
-    Deleted*                    pbDeleted;
+    DeletionWatcher*            m_pDeletionWatcher;
 
     SfxActionListBox			aFmtLb;
     ListBox						aFilterLb;


More information about the Libreoffice-commits mailing list