diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2017-02-26 23:39:25 +0100 |
---|---|---|
committer | Björn Michaelsen <bjoern.michaelsen@canonical.com> | 2017-02-27 10:58:55 +0000 |
commit | ecd77363e0c7760a9d8fd6e3e8dac8099305bb91 (patch) | |
tree | 4df348e6354f75bfe9207e49ce9ee412c290a310 /sw | |
parent | 30a76153fce5fdf578f408828651faab351e5b18 (diff) |
own the SwFlyDrawObj by SwFlyDrawContact w/ unique_ptr
- the code claimed this ownership before
- however it still tried to do stuff in SetMaster(..), which leads to
at least memory leaking, if not worse
- abort there for now
- SetMaster() likely needs to be removed from the base-class proper soon
as not all derived classes can possible implement it.
Change-Id: Id241b9330e6f98a126949a9236c60a8783cf8ea8
Reviewed-on: https://gerrit.libreoffice.org/34663
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/dcontact.hxx | 3 | ||||
-rw-r--r-- | sw/source/core/draw/dcontact.cxx | 16 |
2 files changed, 9 insertions, 10 deletions
diff --git a/sw/inc/dcontact.hxx b/sw/inc/dcontact.hxx index 36f2410321de..e7a34d129083 100644 --- a/sw/inc/dcontact.hxx +++ b/sw/inc/dcontact.hxx @@ -25,6 +25,7 @@ #include <fmtanchr.hxx> #include <frmfmt.hxx> #include <list> +#include <memory> #include "calbck.hxx" #include <anchoreddrawobject.hxx> @@ -189,7 +190,7 @@ public: class SW_DLLPUBLIC SwFlyDrawContact final : public SwContact { private: - SwFlyDrawObj* mpMasterObj; + std::unique_ptr<SwFlyDrawObj> mpMasterObj; void SwClientNotify(const SwModify&, const SfxHint& rHint) override; diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx index 178705ef83d6..5fcde7d522c2 100644 --- a/sw/source/core/draw/dcontact.cxx +++ b/sw/source/core/draw/dcontact.cxx @@ -442,12 +442,12 @@ void SwContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) } -SwFlyDrawContact::SwFlyDrawContact( SwFlyFrameFormat *pToRegisterIn, SdrModel * ) : - SwContact( pToRegisterIn ) +SwFlyDrawContact::SwFlyDrawContact( SwFlyFrameFormat *pToRegisterIn, SdrModel * ) + : SwContact( pToRegisterIn ) + , mpMasterObj(new SwFlyDrawObj) { // #i26791# - class <SwFlyDrawContact> contains the 'master' // drawing object of type <SwFlyDrawObj> on its own. - mpMasterObj = new SwFlyDrawObj; mpMasterObj->SetOrdNum( 0xFFFFFFFE ); mpMasterObj->SetUserCall( this ); } @@ -459,7 +459,6 @@ SwFlyDrawContact::~SwFlyDrawContact() mpMasterObj->SetUserCall( nullptr ); if ( mpMasterObj->GetPage() ) mpMasterObj->GetPage()->RemoveObject( mpMasterObj->GetOrdNum() ); - delete mpMasterObj; } } @@ -484,18 +483,17 @@ SwAnchoredObject* SwFlyDrawContact::GetAnchoredObj(SdrObject *const pSdrObj) const SdrObject* SwFlyDrawContact::GetMaster() const { - return mpMasterObj; + return mpMasterObj.get(); } SdrObject* SwFlyDrawContact::GetMaster() { - return mpMasterObj; + return mpMasterObj.get(); } -void SwFlyDrawContact::SetMaster( SdrObject* _pNewMaster ) +void SwFlyDrawContact::SetMaster( SdrObject* ) { - assert(dynamic_cast<const SwFlyDrawObj*>(_pNewMaster) != nullptr); - mpMasterObj = static_cast<SwFlyDrawObj *>(_pNewMaster); + std::abort(); // this should never be called SwFlyDrawContact is owning its "Master" } /** |