summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2011-06-30 09:20:51 +0200
committerCaolán McNamara <caolanm@redhat.com>2011-06-30 12:04:46 +0100
commit2887257baac6f96aa96b96b954f543c48657a228 (patch)
treea2bea38c912d3666edcf01a141085bf190ada0bb
parent2f835624ffff0f8a8e2a0a13cb18cff70dbde2ac (diff)
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
-rw-r--r--sfx2/source/dialog/templdlg.cxx64
-rw-r--r--sfx2/source/inc/templdgi.hxx16
2 files changed, 55 insertions, 25 deletions
diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx
index 21ca852d547e..625674af4c66 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 c7d4e94d7f19..464a0af94b3d 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;