vcl/generic/print/bitmap_gfx.cxx    |   36 +++++++++++++++---------------------
 vcl/source/app/dbggui.cxx           |    4 ++--
 vcl/source/edit/texteng.cxx         |    5 +++--
 vcl/source/filter/graphicfilter.cxx |   15 ++++++---------
 vcl/source/gdi/bitmapex.cxx         |   19 ++++++-------------
 5 files changed, 32 insertions(+), 47 deletions(-)

New commits:
commit e0e2f4c988af9dc73c7b3ce086efddc0a918406d
Author: Takeshi Abe <t...@fixedpoint.jp>
Date:   Fri Mar 7 16:34:17 2014 +0900

    Avoid possible resource leaks with boost::scoped_ptr
    
    Change-Id: I835bec5c43b7b4a8638d5032b720661fc2f1397f

diff --git a/vcl/generic/print/bitmap_gfx.cxx b/vcl/generic/print/bitmap_gfx.cxx
index 6ea8e33..f929944 100644
--- a/vcl/generic/print/bitmap_gfx.cxx
+++ b/vcl/generic/print/bitmap_gfx.cxx
@@ -23,6 +23,8 @@
 #include "generic/printergfx.hxx"
 #include "vcl/strhelper.hxx"
 
+#include <boost/scoped_ptr.hpp>
+
 namespace psp {
 
 const sal_uInt32 nLineLength = 80;
@@ -489,7 +491,7 @@ PrinterGfx::DrawPS1GrayImage (const PrinterBmp& rBitmap, 
const Rectangle& rArea)
     WritePS (mpPageBody, pGrayImage);
 
     // image body
-    HexEncoder* pEncoder = new HexEncoder (mpPageBody);
+    boost::scoped_ptr<HexEncoder> pEncoder(new HexEncoder (mpPageBody));
 
     for (long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++)
     {
@@ -500,7 +502,7 @@ PrinterGfx::DrawPS1GrayImage (const PrinterBmp& rBitmap, 
const Rectangle& rArea)
         }
     }
 
-    delete pEncoder;
+    pEncoder.reset();
 
     WritePS (mpPageBody, "\n");
 }
@@ -572,8 +574,8 @@ PrinterGfx::writePS2Colorspace(const PrinterBmp& rBitmap, 
psp::ImageType nType)
                 nChar += psp::appendStr ("\npsp_ascii85string\n", pImage + 
nChar);
             WritePS (mpPageBody, pImage);
 
-            ByteEncoder* pEncoder = mbCompressBmp ? new LZWEncoder(mpPageBody)
-                                                  : new 
Ascii85Encoder(mpPageBody);
+            boost::scoped_ptr<ByteEncoder> pEncoder(mbCompressBmp ? new 
LZWEncoder(mpPageBody)
+                                                    : new 
Ascii85Encoder(mpPageBody));
             for (sal_uInt32 i = 0; i < nSize; i++)
             {
                 PrinterColor aColor = rBitmap.GetPaletteColor(i);
@@ -582,7 +584,7 @@ PrinterGfx::writePS2Colorspace(const PrinterBmp& rBitmap, 
psp::ImageType nType)
                 pEncoder->EncodeByte (aColor.GetGreen());
                 pEncoder->EncodeByte (aColor.GetBlue());
             }
-            delete pEncoder;
+            pEncoder.reset();
 
             WritePS (mpPageBody, "pop ] setcolorspace\n");
         }
@@ -597,8 +599,8 @@ PrinterGfx::DrawPS2GrayImage (const PrinterBmp& rBitmap, 
const Rectangle& rArea)
     writePS2Colorspace(rBitmap, psp::GrayScaleImage);
     writePS2ImageHeader(rArea, psp::GrayScaleImage);
 
-    ByteEncoder* pEncoder = mbCompressBmp ? new LZWEncoder(mpPageBody)
-                                          : new Ascii85Encoder(mpPageBody);
+    boost::scoped_ptr<ByteEncoder> pEncoder(mbCompressBmp ? new 
LZWEncoder(mpPageBody)
+                                            : new Ascii85Encoder(mpPageBody));
 
     for (long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++)
     {
@@ -608,8 +610,6 @@ PrinterGfx::DrawPS2GrayImage (const PrinterBmp& rBitmap, 
const Rectangle& rArea)
             pEncoder->EncodeByte (nByte);
         }
     }
-
-    delete pEncoder;
 }
 
 void
@@ -618,8 +618,8 @@ PrinterGfx::DrawPS2MonoImage (const PrinterBmp& rBitmap, 
const Rectangle& rArea)
     writePS2Colorspace(rBitmap, psp::MonochromeImage);
     writePS2ImageHeader(rArea, psp::MonochromeImage);
 
-    ByteEncoder* pEncoder = mbCompressBmp ? new LZWEncoder(mpPageBody)
-                                          : new Ascii85Encoder(mpPageBody);
+    boost::scoped_ptr<ByteEncoder> pEncoder(mbCompressBmp ? new 
LZWEncoder(mpPageBody)
+                                            : new Ascii85Encoder(mpPageBody));
 
     for (long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++)
     {
@@ -643,8 +643,6 @@ PrinterGfx::DrawPS2MonoImage (const PrinterBmp& rBitmap, 
const Rectangle& rArea)
         if (nBitPos != 0)
             pEncoder->EncodeByte (nByte);
     }
-
-    delete pEncoder;
 }
 
 void
@@ -653,8 +651,8 @@ PrinterGfx::DrawPS2PaletteImage (const PrinterBmp& rBitmap, 
const Rectangle& rAr
     writePS2Colorspace(rBitmap, psp::PaletteImage);
     writePS2ImageHeader(rArea, psp::PaletteImage);
 
-    ByteEncoder* pEncoder = mbCompressBmp ? new LZWEncoder(mpPageBody)
-                                          : new Ascii85Encoder(mpPageBody);
+    boost::scoped_ptr<ByteEncoder> pEncoder(mbCompressBmp ? new 
LZWEncoder(mpPageBody)
+                                            : new Ascii85Encoder(mpPageBody));
 
     for (long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++)
     {
@@ -664,8 +662,6 @@ PrinterGfx::DrawPS2PaletteImage (const PrinterBmp& rBitmap, 
const Rectangle& rAr
             pEncoder->EncodeByte (nByte);
         }
     }
-
-    delete pEncoder;
 }
 
 void
@@ -674,8 +670,8 @@ PrinterGfx::DrawPS2TrueColorImage (const PrinterBmp& 
rBitmap, const Rectangle& r
     writePS2Colorspace(rBitmap, psp::TrueColorImage);
     writePS2ImageHeader(rArea, psp::TrueColorImage);
 
-    ByteEncoder* pEncoder = mbCompressBmp ? new LZWEncoder(mpPageBody)
-                                          : new Ascii85Encoder(mpPageBody);
+    boost::scoped_ptr<ByteEncoder> pEncoder(mbCompressBmp ? new 
LZWEncoder(mpPageBody)
+                                            : new Ascii85Encoder(mpPageBody));
 
     for (long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++)
     {
@@ -687,8 +683,6 @@ PrinterGfx::DrawPS2TrueColorImage (const PrinterBmp& 
rBitmap, const Rectangle& r
             pEncoder->EncodeByte (aColor.GetBlue());
         }
     }
-
-    delete pEncoder;
 }
 
 } /* namespace psp */
diff --git a/vcl/source/app/dbggui.cxx b/vcl/source/app/dbggui.cxx
index 4ff4db9..ac2cdd0 100644
--- a/vcl/source/app/dbggui.cxx
+++ b/vcl/source/app/dbggui.cxx
@@ -58,6 +58,7 @@
 
 #include <map>
 #include <algorithm>
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
 
@@ -1649,13 +1650,12 @@ void DbgGUIStart()
 
     if ( pData )
     {
-        DbgDialog* pDialog = new DbgDialog;
+        boost::scoped_ptr<DbgDialog> pDialog(new DbgDialog);
         // we switch off dialog tests for the debug dialog
         sal_uLong nOldFlags = pData->nTestFlags;
         pData->nTestFlags &= ~DBG_TEST_DIALOG;
         if ( !pDialog->Execute() )
             pData->nTestFlags |= (nOldFlags & DBG_TEST_DIALOG);
-        delete pDialog;
     }
     else
     {
diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx
index 5567c90..74fb8bc 100644
--- a/vcl/source/edit/texteng.cxx
+++ b/vcl/source/edit/texteng.cxx
@@ -57,6 +57,7 @@
 #include <set>
 #include <vector>
 #include <boost/foreach.hpp>
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -615,7 +616,7 @@ TextPaM TextEngine::ImpDeleteText( const TextSelection& 
rSel )
 void TextEngine::ImpRemoveParagraph( sal_uLong nPara )
 {
     TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
-    TEParaPortion* pPortion = mpTEParaPortions->GetObject( nPara );
+    boost::scoped_ptr<TEParaPortion> pPortion(mpTEParaPortions->GetObject( 
nPara ));
 
     // the Node is handled by Undo and is deleted if appropriate
     mpDoc->GetNodes().Remove( nPara );
@@ -625,7 +626,7 @@ void TextEngine::ImpRemoveParagraph( sal_uLong nPara )
         delete pNode;
 
     mpTEParaPortions->Remove( nPara );
-    delete pPortion;
+    pPortion.reset();
 
     ImpParagraphRemoved( nPara );
 }
diff --git a/vcl/source/filter/graphicfilter.cxx 
b/vcl/source/filter/graphicfilter.cxx
index c3a4454..7840d61 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -63,6 +63,7 @@
 #include <rtl/instance.hxx>
 #include <vcl/metaact.hxx>
 #include <vector>
+#include <boost/scoped_ptr.hpp>
 
 #include "FilterConfigCache.hxx"
 
@@ -828,7 +829,7 @@ static Graphic ImpGetScaledGraphic( const Graphic& 
rGraphic, FilterConfigItem& r
 {
     Graphic     aGraphic;
 
-    ResMgr*     pResMgr = ResMgr::CreateResMgr( "svt", 
Application::GetSettings().GetUILanguageTag() );
+    boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "svt", 
Application::GetSettings().GetUILanguageTag() ));
 
     sal_Int32 nLogicalWidth = rConfigItem.ReadInt32( "LogicalWidth", 0 );
     sal_Int32 nLogicalHeight = rConfigItem.ReadInt32( "LogicalHeight", 0 );
@@ -919,8 +920,6 @@ static Graphic ImpGetScaledGraphic( const Graphic& 
rGraphic, FilterConfigItem& r
     else
         aGraphic = rGraphic;
 
-    delete pResMgr;
-
     return aGraphic;
 }
 
@@ -1289,11 +1288,10 @@ sal_uInt16 GraphicFilter::CanImportGraphic( const 
INetURLObject& rPath,
     DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, 
"GraphicFilter::CanImportGraphic() : ProtType == INET_PROT_NOT_VALID" );
 
     OUString    aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) );
-    SvStream*   pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, 
STREAM_READ | STREAM_SHARE_DENYNONE );
+    boost::scoped_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( 
aMainUrl, STREAM_READ | STREAM_SHARE_DENYNONE ));
     if ( pStream )
     {
         nRetValue = CanImportGraphic( aMainUrl, *pStream, nFormat, 
pDeterminedFormat );
-        delete pStream;
     }
     return nRetValue;
 }
@@ -1320,11 +1318,10 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& 
rGraphic, const INetURLObject&
     DBG_ASSERT( rPath.GetProtocol() != INET_PROT_NOT_VALID, 
"GraphicFilter::ImportGraphic() : ProtType == INET_PROT_NOT_VALID" );
 
     OUString    aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) );
-    SvStream*   pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, 
STREAM_READ | STREAM_SHARE_DENYNONE );
+    boost::scoped_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( 
aMainUrl, STREAM_READ | STREAM_SHARE_DENYNONE ));
     if ( pStream )
     {
         nRetValue = ImportGraphic( rGraphic, aMainUrl, *pStream, nFormat, 
pDeterminedFormat, nImportFlags );
-        delete pStream;
     }
     return nRetValue;
 }
@@ -1816,11 +1813,11 @@ sal_uInt16 GraphicFilter::ExportGraphic( const Graphic& 
rGraphic, const INetURLO
     bool bAlreadyExists = DirEntryExists( rPath );
 
     OUString    aMainUrl( rPath.GetMainURL( INetURLObject::NO_DECODE ) );
-    SvStream*   pStream = ::utl::UcbStreamHelper::CreateStream( aMainUrl, 
STREAM_WRITE | STREAM_TRUNC );
+    boost::scoped_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( 
aMainUrl, STREAM_WRITE | STREAM_TRUNC ));
     if ( pStream )
     {
         nRetValue = ExportGraphic( rGraphic, aMainUrl, *pStream, nFormat, 
pFilterData );
-        delete pStream;
+        pStream.reset();
 
         if( ( GRFILTER_OK != nRetValue ) && !bAlreadyExists )
             KillDirEntry( aMainUrl );
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index b9a6311..8eb4613 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -44,6 +44,7 @@
 #include <salinst.hxx>
 #include <svdata.hxx>
 #include <com/sun/star/beans/XFastPropertySet.hpp>
+#include <boost/scoped_ptr.hpp>
 using namespace ::com::sun::star;
 
 BitmapEx::BitmapEx() :
@@ -793,11 +794,10 @@ bool BitmapEx::Create( const 
::com::sun::star::uno::Reference<
     {
         // 0 means get BitmapEx
         uno::Any aAny = xFastPropertySet->getFastPropertyValue( 0 );
-        BitmapEx* pBitmapEx = (BitmapEx*) *reinterpret_cast<const 
sal_Int64*>(aAny.getValue());
+        boost::scoped_ptr<BitmapEx> pBitmapEx((BitmapEx*) 
*reinterpret_cast<const sal_Int64*>(aAny.getValue()));
         if( pBitmapEx )
         {
             *this = *pBitmapEx;
-            delete pBitmapEx;
             return true;
         }
     }
@@ -839,12 +839,12 @@ namespace
         bool bSmooth)
     {
         Bitmap aDestination(aDestinationSize, 24);
-        BitmapWriteAccess* pWrite = aDestination.AcquireWriteAccess();
+        boost::scoped_ptr<BitmapWriteAccess> 
pWrite(aDestination.AcquireWriteAccess());
 
         if(pWrite)
         {
             //const Size aContentSizePixel(rSource.GetSizePixel());
-            BitmapReadAccess* pRead = (const_cast< Bitmap& 
>(rSource)).AcquireReadAccess();
+            boost::scoped_ptr<BitmapReadAccess> pRead((const_cast< Bitmap& 
>(rSource)).AcquireReadAccess());
 
             if(pRead)
             {
@@ -881,11 +881,7 @@ namespace
                         }
                     }
                 }
-
-                delete pRead;
             }
-
-            delete pWrite;
         }
 
         rSource.AdaptBitCount(aDestination);
@@ -1032,7 +1028,7 @@ BitmapEx BitmapEx::ModifyBitmapEx(const 
basegfx::BColorModifierStack& rBColorMod
                     // do NOT use erase; for e.g. 8bit Bitmaps, the nearest 
color to the given
                     // erase color is determined and used -> this may be 
different from what is
                     // wanted here. Better create a new bitmap with the needed 
color explicitely
-                    BitmapReadAccess* pReadAccess = 
aChangedBitmap.AcquireReadAccess();
+                    boost::scoped_ptr<BitmapReadAccess> 
pReadAccess(aChangedBitmap.AcquireReadAccess());
                     OSL_ENSURE(pReadAccess, "Got no Bitmap ReadAccess ?!?");
 
                     if(pReadAccess)
@@ -1043,7 +1039,6 @@ BitmapEx BitmapEx::ModifyBitmapEx(const 
basegfx::BColorModifierStack& rBColorMod
                             aChangedBitmap.GetSizePixel(),
                             aChangedBitmap.GetBitCount(),
                             &aNewPalette);
-                        delete pReadAccess;
                     }
                 }
                 else
@@ -1061,7 +1056,7 @@ BitmapEx BitmapEx::ModifyBitmapEx(const 
basegfx::BColorModifierStack& rBColorMod
         }
         else
         {
-            BitmapWriteAccess* pContent = aChangedBitmap.AcquireWriteAccess();
+            boost::scoped_ptr<BitmapWriteAccess> 
pContent(aChangedBitmap.AcquireWriteAccess());
 
             if(pContent)
             {
@@ -1137,8 +1132,6 @@ BitmapEx BitmapEx::ModifyBitmapEx(const 
basegfx::BColorModifierStack& rBColorMod
                         }
                     }
                 }
-
-                delete pContent;
             }
         }
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to