[Libreoffice-commits] core.git: 2 commits - editeng/source

Caolán McNamara caolanm at redhat.com
Fri Nov 11 14:47:49 UTC 2016


 editeng/source/items/frmitems.cxx |  112 +++++++++++++++++---------------------
 1 file changed, 52 insertions(+), 60 deletions(-)

New commits:
commit af92221020fa2ef4d51fb4301e6878286a37ccca
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Nov 11 11:03:20 2016 +0000

    this looks like a leak to me
    
    Change-Id: Id72d770ec55d6e627a81cc9590cb59f6c84f27b9

diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx
index 4c55a69..a6618ea 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -3267,12 +3267,11 @@ public:
     std::unique_ptr<GraphicObject> xGraphicObject;
     sal_Int8        nGraphicTransparency; //contains a percentage value which is
                                           //copied to the GraphicObject when necessary
-    SvStream*       pStream;
+    std::unique_ptr<SvStream> xStream;
 
     explicit SvxBrushItem_Impl(GraphicObject* p)
         : xGraphicObject(p)
         , nGraphicTransparency(0)
-        , pStream(nullptr)
     {
     }
 };
@@ -3841,7 +3840,7 @@ SvStream& SvxBrushItem::Store( SvStream& rStream , sal_uInt16 /*nItemVersion*/ )
 
 void SvxBrushItem::PurgeMedium() const
 {
-    DELETEZ( pImpl->pStream );
+    pImpl->xStream.reset();
 }
 
 const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) const
@@ -3858,13 +3857,13 @@ const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) co
         bool bGraphicLoaded = false;
 
         // try to create stream directly from given URL
-        pImpl->pStream = utl::UcbStreamHelper::CreateStream( maStrLink, StreamMode::STD_READ );
+        pImpl->xStream.reset(utl::UcbStreamHelper::CreateStream(maStrLink, StreamMode::STD_READ));
 
         // tdf#94088 if we have a stream, try to load it directly as graphic
-        if( pImpl->pStream && !pImpl->pStream->GetError() )
+        if (pImpl->xStream && !pImpl->xStream->GetError())
         {
-            if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, maStrLink, *pImpl->pStream,
-                GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::DontSetLogsizeForJpeg ))
+            if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, maStrLink, *pImpl->xStream,
+                GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::DontSetLogsizeForJpeg))
             {
                 bGraphicLoaded = true;
             }
@@ -3878,10 +3877,10 @@ const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) co
 
             if( INetProtocol::Data == aGraphicURL.GetProtocol() )
             {
-                std::unique_ptr<SvMemoryStream> const pStream(aGraphicURL.getData());
-                if (pStream)
+                std::unique_ptr<SvMemoryStream> const xStream(aGraphicURL.getData());
+                if (xStream)
                 {
-                    if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream))
+                    if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *xStream))
                     {
                         bGraphicLoaded = true;
 
commit edff2837c36ea736a0a206e56f92de23e19f19b3
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Nov 11 10:58:27 2016 +0000

    use std::unique_ptr
    
    Change-Id: I03e2fb2d3ad1b0b7e64f93dbee172b119ef7bf40

diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx
index 7de28e3..4c55a69 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -3264,12 +3264,17 @@ void SvxLineItem::SetLine( const SvxBorderLine* pNew )
 class SvxBrushItem_Impl
 {
 public:
-    GraphicObject*  pGraphicObject;
+    std::unique_ptr<GraphicObject> xGraphicObject;
     sal_Int8        nGraphicTransparency; //contains a percentage value which is
                                           //copied to the GraphicObject when necessary
     SvStream*       pStream;
 
-    explicit SvxBrushItem_Impl( GraphicObject* p ) : pGraphicObject( p ), nGraphicTransparency(0), pStream(nullptr) {}
+    explicit SvxBrushItem_Impl(GraphicObject* p)
+        : xGraphicObject(p)
+        , nGraphicTransparency(0)
+        , pStream(nullptr)
+    {
+    }
 };
 
 
@@ -3439,7 +3444,7 @@ SvxBrushItem::SvxBrushItem( SvStream& rStream, sal_uInt16 nVersion,
             Graphic aGraphic;
 
             ReadGraphic( rStream, aGraphic );
-            pImpl->pGraphicObject = new GraphicObject( aGraphic );
+            pImpl->xGraphicObject.reset(new GraphicObject(aGraphic));
 
             if( SVSTREAM_FILEFORMAT_ERROR == rStream.GetError() )
             {
@@ -3488,13 +3493,10 @@ SvxBrushItem::SvxBrushItem( const SvxBrushItem& rItem ) :
     *this = rItem;
 }
 
-
 SvxBrushItem::~SvxBrushItem()
 {
-    delete pImpl->pGraphicObject;
 }
 
-
 sal_uInt16 SvxBrushItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
 {
     return BRUSH_GRAPHIC_VERSION;
@@ -3545,12 +3547,12 @@ bool SvxBrushItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
             OUString sLink;
             if ( !maStrLink.isEmpty() )
                 sLink = maStrLink;
-            else if( pImpl->pGraphicObject )
+            else if (pImpl->xGraphicObject)
             {
                 OUString sPrefix(
                     UNO_NAME_GRAPHOBJ_URLPREFIX);
                 OUString sId(OStringToOUString(
-                    pImpl->pGraphicObject->GetUniqueID(),
+                    pImpl->xGraphicObject->GetUniqueID(),
                     RTL_TEXTENCODING_ASCII_US));
                 sLink = sPrefix + sId;
             }
@@ -3644,10 +3646,10 @@ bool SvxBrushItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
                     maStrLink.clear();
                     OString sId(OUStringToOString(sLink.copy( sizeof(UNO_NAME_GRAPHOBJ_URLPREFIX)-1 ),
                                                   RTL_TEXTENCODING_ASCII_US));
-                    GraphicObject *pOldGrfObj = pImpl->pGraphicObject;
-                    pImpl->pGraphicObject = new GraphicObject( sId );
+                    std::unique_ptr<GraphicObject> xOldGrfObj(std::move(pImpl->xGraphicObject));
+                    pImpl->xGraphicObject.reset(new GraphicObject(sId));
                     ApplyGraphicTransparency_Impl();
-                    delete pOldGrfObj;
+                    xOldGrfObj.reset();
                 }
                 else
                 {
@@ -3678,7 +3680,7 @@ bool SvxBrushItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
             if(nTmp >= 0 && nTmp <= 100)
             {
                 pImpl->nGraphicTransparency = sal_Int8(nTmp);
-                if(pImpl->pGraphicObject)
+                if (pImpl->xGraphicObject)
                     ApplyGraphicTransparency_Impl();
             }
         }
@@ -3724,13 +3726,12 @@ bool SvxBrushItem::GetPresentation
     return true;
 }
 
-
-SvxBrushItem& SvxBrushItem::operator=( const SvxBrushItem& rItem )
+SvxBrushItem& SvxBrushItem::operator=(const SvxBrushItem& rItem)
 {
     aColor = rItem.aColor;
     eGraphicPos = rItem.eGraphicPos;
 
-    DELETEZ( pImpl->pGraphicObject );
+    pImpl->xGraphicObject.reset();
     maStrLink.clear();
     maStrFilter.clear();
 
@@ -3738,9 +3739,9 @@ SvxBrushItem& SvxBrushItem::operator=( const SvxBrushItem& rItem )
     {
         maStrLink = rItem.maStrLink;
         maStrFilter = rItem.maStrFilter;
-        if ( rItem.pImpl->pGraphicObject )
+        if (rItem.pImpl->xGraphicObject)
         {
-            pImpl->pGraphicObject = new GraphicObject( *rItem.pImpl->pGraphicObject );
+            pImpl->xGraphicObject.reset(new GraphicObject(*rItem.pImpl->xGraphicObject));
         }
     }
 
@@ -3772,11 +3773,11 @@ bool SvxBrushItem::operator==( const SfxPoolItem& rAttr ) const
 
             if ( bEqual )
             {
-                if ( !rCmp.pImpl->pGraphicObject )
-                    bEqual = !pImpl->pGraphicObject;
+                if (!rCmp.pImpl->xGraphicObject)
+                    bEqual = !pImpl->xGraphicObject;
                 else
-                    bEqual = pImpl->pGraphicObject &&
-                             ( *pImpl->pGraphicObject == *rCmp.pImpl->pGraphicObject );
+                    bEqual = pImpl->xGraphicObject &&
+                             (*pImpl->xGraphicObject == *rCmp.pImpl->xGraphicObject);
             }
         }
 
@@ -3811,7 +3812,7 @@ SvStream& SvxBrushItem::Store( SvStream& rStream , sal_uInt16 /*nItemVersion*/ )
 
     sal_uInt16 nDoLoad = 0;
 
-    if ( pImpl->pGraphicObject && maStrLink.isEmpty() )
+    if (pImpl->xGraphicObject && maStrLink.isEmpty())
         nDoLoad |= LOAD_GRAPHIC;
     if ( !maStrLink.isEmpty() )
         nDoLoad |= LOAD_LINK;
@@ -3819,8 +3820,8 @@ SvStream& SvxBrushItem::Store( SvStream& rStream , sal_uInt16 /*nItemVersion*/ )
         nDoLoad |= LOAD_FILTER;
     rStream.WriteUInt16( nDoLoad );
 
-    if ( pImpl->pGraphicObject && maStrLink.isEmpty() )
-        WriteGraphic( rStream, pImpl->pGraphicObject->GetGraphic() );
+    if (pImpl->xGraphicObject && maStrLink.isEmpty())
+        WriteGraphic(rStream, pImpl->xGraphicObject->GetGraphic());
     if ( !maStrLink.isEmpty() )
     {
         OSL_FAIL("No BaseURL!");
@@ -3838,16 +3839,14 @@ SvStream& SvxBrushItem::Store( SvStream& rStream , sal_uInt16 /*nItemVersion*/ )
     return rStream;
 }
 
-
 void SvxBrushItem::PurgeMedium() const
 {
     DELETEZ( pImpl->pStream );
 }
 
-
 const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) const
 {
-    if ( bLoadAgain && !maStrLink.isEmpty() && !pImpl->pGraphicObject )
+    if (bLoadAgain && !maStrLink.isEmpty() && !pImpl->xGraphicObject)
     // when graphics already loaded, use as a cache
     {
         if (SvtSecurityOptions().isUntrustedReferer(referer)) {
@@ -3897,8 +3896,8 @@ const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) co
         // tdf#94088 when we got a graphic, set it
         if(bGraphicLoaded && GraphicType::NONE != aGraphic.GetType())
         {
-            pImpl->pGraphicObject = new GraphicObject;
-            pImpl->pGraphicObject->SetGraphic( aGraphic );
+            pImpl->xGraphicObject.reset(new GraphicObject);
+            pImpl->xGraphicObject->SetGraphic(aGraphic);
             const_cast < SvxBrushItem*> (this)->ApplyGraphicTransparency_Impl();
         }
         else
@@ -3907,10 +3906,9 @@ const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) co
         }
     }
 
-    return pImpl->pGraphicObject;
+    return pImpl->xGraphicObject.get();
 }
 
-
 sal_Int8 SvxBrushItem::getGraphicTransparency() const
 {
     return pImpl->nGraphicTransparency;
@@ -3940,15 +3938,15 @@ void SvxBrushItem::SetGraphicPos( SvxGraphicPosition eNew )
 
     if ( GPOS_NONE == eGraphicPos )
     {
-        DELETEZ( pImpl->pGraphicObject );
+        pImpl->xGraphicObject.reset();
         maStrLink.clear();
         maStrFilter.clear();
     }
     else
     {
-        if ( !pImpl->pGraphicObject && maStrLink.isEmpty() )
+        if (!pImpl->xGraphicObject && maStrLink.isEmpty())
         {
-            pImpl->pGraphicObject = new GraphicObject; // Creating a dummy
+            pImpl->xGraphicObject.reset(new GraphicObject); // Creating a dummy
         }
     }
 }
@@ -3958,10 +3956,10 @@ void SvxBrushItem::SetGraphic( const Graphic& rNew )
 {
     if ( maStrLink.isEmpty() )
     {
-        if ( pImpl->pGraphicObject )
-            pImpl->pGraphicObject->SetGraphic( rNew );
+        if (pImpl->xGraphicObject)
+            pImpl->xGraphicObject->SetGraphic(rNew);
         else
-            pImpl->pGraphicObject = new GraphicObject( rNew );
+            pImpl->xGraphicObject.reset(new GraphicObject(rNew));
 
         ApplyGraphicTransparency_Impl();
 
@@ -3979,10 +3977,10 @@ void SvxBrushItem::SetGraphicObject( const GraphicObject& rNewObj )
 {
     if ( maStrLink.isEmpty() )
     {
-        if ( pImpl->pGraphicObject )
-            *pImpl->pGraphicObject = rNewObj;
+        if (pImpl->xGraphicObject)
+            *pImpl->xGraphicObject = rNewObj;
         else
-            pImpl->pGraphicObject = new GraphicObject( rNewObj );
+            pImpl->xGraphicObject.reset(new GraphicObject(rNewObj));
 
         ApplyGraphicTransparency_Impl();
 
@@ -4003,17 +4001,15 @@ void SvxBrushItem::SetGraphicLink( const OUString& rNew )
     else
     {
         maStrLink = rNew;
-        DELETEZ( pImpl->pGraphicObject );
+        pImpl->xGraphicObject.reset();
     }
 }
 
-
 void SvxBrushItem::SetGraphicFilter( const OUString& rNew )
 {
     maStrFilter = rNew;
 }
 
-
 SvxGraphicPosition SvxBrushItem::WallpaperStyle2GraphicPos( WallpaperStyle eStyle )
 {
     SvxGraphicPosition eResult;
@@ -4037,7 +4033,6 @@ SvxGraphicPosition SvxBrushItem::WallpaperStyle2GraphicPos( WallpaperStyle eStyl
     return eResult;
 };
 
-
 WallpaperStyle SvxBrushItem::GraphicPos2WallpaperStyle( SvxGraphicPosition ePos )
 {
     WallpaperStyle eResult;
@@ -4082,20 +4077,18 @@ SvxBrushItem::SvxBrushItem( const CntWallpaperItem& rItem, sal_uInt16 _nWhich )
     }
 }
 
-
-void  SvxBrushItem::ApplyGraphicTransparency_Impl()
+void SvxBrushItem::ApplyGraphicTransparency_Impl()
 {
-    DBG_ASSERT(pImpl->pGraphicObject, "no GraphicObject available" );
-    if(pImpl->pGraphicObject)
+    DBG_ASSERT(pImpl->xGraphicObject, "no GraphicObject available" );
+    if (pImpl->xGraphicObject)
     {
-        GraphicAttr aAttr(pImpl->pGraphicObject->GetAttr());
+        GraphicAttr aAttr(pImpl->xGraphicObject->GetAttr());
         aAttr.SetTransparency(lcl_PercentToTransparency(
                             pImpl->nGraphicTransparency));
-        pImpl->pGraphicObject->SetAttr(aAttr);
+        pImpl->xGraphicObject->SetAttr(aAttr);
     }
 }
 
-
 void SvxBrushItem::dumpAsXml(xmlTextWriterPtr pWriter) const
 {
     xmlTextWriterStartElement(pWriter, BAD_CAST("svxBrushItem"));


More information about the Libreoffice-commits mailing list