[Libreoffice-commits] core.git: sw/inc sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Mon Feb 27 10:59:29 UTC 2017


 sw/inc/dcontact.hxx              |    3 ++-
 sw/source/core/draw/dcontact.cxx |   16 +++++++---------
 2 files changed, 9 insertions(+), 10 deletions(-)

New commits:
commit ecd77363e0c7760a9d8fd6e3e8dac8099305bb91
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sun Feb 26 23:39:25 2017 +0100

    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 at libreoffice.org>
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sw/inc/dcontact.hxx b/sw/inc/dcontact.hxx
index 36f2410..e7a34d1 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 178705e..5fcde7d 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"
 }
 
 /**


More information about the Libreoffice-commits mailing list