svx/source/unodraw/unoshape.cxx |   25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

New commits:
commit fc2b0215b9a1db1ab78bec4b7cab44f4fbdf91f4
Author: Armin Le Grand <armin.le.gr...@cib.de>
Date:   Wed Apr 4 13:01:01 2018 +0200

    SOSAW080: Free SdrObjects when SdrModel goes down
    
    In an UNO API test problem is that SvxShapes reference
    SdrShapes, but these are not added to a SdrPage and not
    'owned' by the SvxShape. Thus these do not get deleted
    at all (same in master, memory leak). I extended
    SvxShape::Notify the case for ModelCleared to also
    Free the SdrObject when not owner and it's not added to
    a SdrPage (in that case it gets deleted with deleting
    the SdrModel)
    
    Change-Id: I7b5c241faec7488924e5935ae8b19f785846b5e4

diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index 506e6143f1e0..c48b0c8bfc6c 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -1019,17 +1019,30 @@ void SvxShape::Notify( SfxBroadcaster&, const SfxHint& 
rHint ) throw()
 
     if( bClearMe )
     {
-        if( !HasSdrObjectOwnership() ) {
-            if( HasSdrObject() )
+        SdrObject* pSdrObject(GetSdrObject());
+
+        if(!HasSdrObjectOwnership())
+        {
+            if(nullptr != pSdrObject)
             {
-                EndListening(GetSdrObject()->getSdrModelFromSdrObject());
-                GetSdrObject()->setUnoShape( nullptr );
+                EndListening(pSdrObject->getSdrModelFromSdrObject());
+                pSdrObject->setUnoShape(nullptr);
             }
 
-            mpSdrObjectWeakReference.reset( nullptr );
+            mpSdrObjectWeakReference.reset(nullptr);
+
+            // SdrModel *is* going down, try to Free SdrObject even
+            // when !HasSdrObjectOwnership
+            if(nullptr != pSdrObject && !pSdrObject->IsInserted())
+            {
+                SdrObject::Free(pSdrObject);
+            }
         }
-        if ( !mpImpl->mbDisposing )
+
+        if(!mpImpl->mbDisposing)
+        {
             dispose();
+        }
     }
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to