[Libreoffice-commits] core.git: vcl/source
Takeshi Abe
tabe at fixedpoint.jp
Tue Mar 18 16:29:11 PDT 2014
vcl/source/gdi/impimage.cxx | 10 ++++------
vcl/source/gdi/impvect.cxx | 9 +++------
vcl/source/gdi/jobset.cxx | 10 +++++-----
vcl/source/gdi/outdev2.cxx | 30 +++++++++++-------------------
vcl/source/gdi/outdev4.cxx | 22 +++++++++-------------
5 files changed, 32 insertions(+), 49 deletions(-)
New commits:
commit bbdbf199ebfd26f1844500bf175444c35885a2b4
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Tue Mar 18 23:07:13 2014 +0900
Avoid possible resource leaks by boost::scoped_array
Change-Id: I97dc3d073cca1584f195b592cec9ef2d8d0dbd23
diff --git a/vcl/source/gdi/impimage.cxx b/vcl/source/gdi/impimage.cxx
index 5215ed0..9f1333f 100644
--- a/vcl/source/gdi/impimage.cxx
+++ b/vcl/source/gdi/impimage.cxx
@@ -28,6 +28,7 @@
#include <vcl/settings.hxx>
#include <image.h>
+#include <boost/scoped_array.hpp>
#define IMPSYSIMAGEITEM_MASK ( 0x01 )
#define IMPSYSIMAGEITEM_ALPHA ( 0x02 )
@@ -211,9 +212,9 @@ void ImplImageBmp::Draw( sal_uInt16 nPos, OutputDevice* pOutDev,
BitmapColor aCol;
const long nW = pAcc->Width();
const long nH = pAcc->Height();
- sal_uInt8* pMapR = new sal_uInt8[ 256 ];
- sal_uInt8* pMapG = new sal_uInt8[ 256 ];
- sal_uInt8* pMapB = new sal_uInt8[ 256 ];
+ boost::scoped_array<sal_uInt8> pMapR(new sal_uInt8[ 256 ]);
+ boost::scoped_array<sal_uInt8> pMapG(new sal_uInt8[ 256 ]);
+ boost::scoped_array<sal_uInt8> pMapB(new sal_uInt8[ 256 ]);
long nX, nY;
if( nStyle & IMAGE_DRAW_HIGHLIGHT )
@@ -272,9 +273,6 @@ void ImplImageBmp::Draw( sal_uInt16 nPos, OutputDevice* pOutDev,
}
}
- delete[] pMapR;
- delete[] pMapG;
- delete[] pMapB;
aTmpBmp.ReleaseAccess( pAcc );
}
}
diff --git a/vcl/source/gdi/impvect.cxx b/vcl/source/gdi/impvect.cxx
index 739fc8a..317c6c9 100644
--- a/vcl/source/gdi/impvect.cxx
+++ b/vcl/source/gdi/impvect.cxx
@@ -27,6 +27,7 @@
#include <vcl/wrkwin.hxx>
#include <vcl/virdev.hxx>
#include <impvect.hxx>
+#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
#define VECT_POLY_MAX 8192
@@ -880,8 +881,8 @@ ImplVectMap* ImplVectorizer::ImplExpand( BitmapReadAccess* pRAcc, const Color& r
const long nNewWidth = ( nOldWidth << 2L ) + 4L;
const long nNewHeight = ( nOldHeight << 2L ) + 4L;
const BitmapColor aTest( pRAcc->GetBestMatchingColor( rColor ) );
- long* pMapIn = new long[ std::max( nOldWidth, nOldHeight ) ];
- long* pMapOut = new long[ std::max( nOldWidth, nOldHeight ) ];
+ boost::scoped_array<long> pMapIn(new long[ std::max( nOldWidth, nOldHeight ) ]);
+ boost::scoped_array<long> pMapOut(new long[ std::max( nOldWidth, nOldHeight ) ]);
long nX, nY, nTmpX, nTmpY;
pMap = new ImplVectMap( nNewWidth, nNewHeight );
@@ -951,10 +952,6 @@ ImplVectMap* ImplVectorizer::ImplExpand( BitmapReadAccess* pRAcc, const Color& r
nY++;
}
}
-
- // cleanup
- delete[] pMapIn;
- delete[] pMapOut;
}
return pMap;
diff --git a/vcl/source/gdi/jobset.cxx b/vcl/source/gdi/jobset.cxx
index ecc8175..15e49df 100644
--- a/vcl/source/gdi/jobset.cxx
+++ b/vcl/source/gdi/jobset.cxx
@@ -24,6 +24,7 @@
#include <vcl/jobset.hxx>
#include <jobset.h>
+#include <boost/scoped_array.hpp>
#define JOBSET_FILE364_SYSTEM ((sal_uInt16)0xFFFF)
@@ -236,11 +237,11 @@ SvStream& ReadJobSetup( SvStream& rIStream, JobSetup& rJobSetup )
sal_uInt16 nSystem = 0;
rIStream.ReadUInt16( nSystem );
- char* pTempBuf = new char[nLen];
- rIStream.Read( pTempBuf, nLen - sizeof( nLen ) - sizeof( nSystem ) );
+ boost::scoped_array<char> pTempBuf(new char[nLen]);
+ rIStream.Read( pTempBuf.get(), nLen - sizeof( nLen ) - sizeof( nSystem ) );
if ( nLen >= sizeof(ImplOldJobSetupData)+4 )
{
- ImplOldJobSetupData* pData = (ImplOldJobSetupData*)pTempBuf;
+ ImplOldJobSetupData* pData = (ImplOldJobSetupData*)pTempBuf.get();
if ( rJobSetup.mpData )
{
if ( rJobSetup.mpData->mnRefCount == 1 )
@@ -262,7 +263,7 @@ SvStream& ReadJobSetup( SvStream& rIStream, JobSetup& rJobSetup )
if ( nSystem == JOBSET_FILE364_SYSTEM ||
nSystem == JOBSET_FILE605_SYSTEM )
{
- Impl364JobSetupData* pOldJobData = (Impl364JobSetupData*)(pTempBuf + sizeof( ImplOldJobSetupData ));
+ Impl364JobSetupData* pOldJobData = (Impl364JobSetupData*)(pTempBuf.get() + sizeof( ImplOldJobSetupData ));
sal_uInt16 nOldJobDataSize = SVBT16ToShort( pOldJobData->nSize );
pJobData->mnSystem = SVBT16ToShort( pOldJobData->nSystem );
pJobData->mnDriverDataLen = SVBT32ToUInt32( pOldJobData->nDriverDataLen );
@@ -305,7 +306,6 @@ SvStream& ReadJobSetup( SvStream& rIStream, JobSetup& rJobSetup )
}
}
}
- delete[] pTempBuf;
}
return rIStream;
diff --git a/vcl/source/gdi/outdev2.cxx b/vcl/source/gdi/outdev2.cxx
index b3d074b..235a0c8 100644
--- a/vcl/source/gdi/outdev2.cxx
+++ b/vcl/source/gdi/outdev2.cxx
@@ -38,7 +38,7 @@
#include <outdata.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
-
+#include <boost/scoped_array.hpp>
#define OUTDEV_INIT() \
{ \
@@ -1671,13 +1671,12 @@ void OutputDevice::DrawPixel( const Polygon& rPts, const Color& rColor )
if( rColor != COL_TRANSPARENT && ! ImplIsRecordLayout() )
{
const sal_uInt16 nSize = rPts.GetSize();
- Color* pColArray = new Color[ nSize ];
+ boost::scoped_array<Color> pColArray(new Color[ nSize ]);
for( sal_uInt16 i = 0; i < nSize; i++ )
pColArray[ i ] = rColor;
- DrawPixel( rPts, pColArray );
- delete[] pColArray;
+ DrawPixel( rPts, pColArray.get() );
}
if( mpAlphaVDev )
@@ -2097,8 +2096,8 @@ void OutputDevice::ImplDrawAlpha( const Bitmap& rBmp, const AlphaMask& rAlpha,
long nX, nOutX, nY, nOutY;
long nMirrOffX = 0;
long nMirrOffY = 0;
- long* pMapX = new long[ nDstWidth ];
- long* pMapY = new long[ nDstHeight ];
+ boost::scoped_array<long> pMapX(new long[ nDstWidth ]);
+ boost::scoped_array<long> pMapY(new long[ nDstHeight ]);
// create horizontal mapping table
if( bHMirr )
@@ -2142,7 +2141,7 @@ void OutputDevice::ImplDrawAlpha( const Bitmap& rBmp, const AlphaMask& rAlpha,
aDstRect,
nOffY,nDstHeight,
nOffX,nDstWidth,
- pMapX,pMapY );
+ pMapX.get(),pMapY.get() );
}
else
{
@@ -2152,7 +2151,7 @@ void OutputDevice::ImplDrawAlpha( const Bitmap& rBmp, const AlphaMask& rAlpha,
nOffX,nDstWidth,
aBmpRect,aOutSz,
bHMirr,bVMirr,
- pMapX,pMapY );
+ pMapX.get(),pMapY.get() );
}
// #110958# Disable alpha VDev, we're doing the necessary
@@ -2170,8 +2169,6 @@ void OutputDevice::ImplDrawAlpha( const Bitmap& rBmp, const AlphaMask& rAlpha,
( (Bitmap&) rBmp ).ReleaseAccess( pP );
( (AlphaMask&) rAlpha ).ReleaseAccess( pA );
- delete[] pMapX;
- delete[] pMapY;
mbMap = bOldMap;
mpMetaFile = pOldMetaFile;
}
@@ -2237,8 +2234,8 @@ void OutputDevice::ImplPrintTransparent( const Bitmap& rBmp, const Bitmap& rMask
// do painting
const long nSrcWidth = aSrcRect.GetWidth(), nSrcHeight = aSrcRect.GetHeight();
long nX, nY; // , nWorkX, nWorkY, nWorkWidth, nWorkHeight;
- long* pMapX = new long[ nSrcWidth + 1 ];
- long* pMapY = new long[ nSrcHeight + 1 ];
+ boost::scoped_array<long> pMapX(new long[ nSrcWidth + 1 ]);
+ boost::scoped_array<long> pMapY(new long[ nSrcHeight + 1 ]);
const bool bOldMap = mbMap;
mbMap = false;
@@ -2284,9 +2281,6 @@ void OutputDevice::ImplPrintTransparent( const Bitmap& rBmp, const Bitmap& rMask
//}
mbMap = bOldMap;
-
- delete[] pMapX;
- delete[] pMapY;
}
}
@@ -2336,8 +2330,8 @@ void OutputDevice::ImplPrintMask( const Bitmap& rMask, const Color& rMaskColor,
// do painting
const long nSrcWidth = aSrcRect.GetWidth(), nSrcHeight = aSrcRect.GetHeight();
long nX, nY; //, nWorkX, nWorkY, nWorkWidth, nWorkHeight;
- long* pMapX = new long[ nSrcWidth + 1 ];
- long* pMapY = new long[ nSrcHeight + 1 ];
+ boost::scoped_array<long> pMapX(new long[ nSrcWidth + 1 ]);
+ boost::scoped_array<long> pMapY(new long[ nSrcHeight + 1 ]);
GDIMetaFile* pOldMetaFile = mpMetaFile;
const bool bOldMap = mbMap;
@@ -2385,8 +2379,6 @@ void OutputDevice::ImplPrintMask( const Bitmap& rMask, const Color& rMaskColor,
//}
Pop();
- delete[] pMapX;
- delete[] pMapY;
mbMap = bOldMap;
mpMetaFile = pOldMetaFile;
}
diff --git a/vcl/source/gdi/outdev4.cxx b/vcl/source/gdi/outdev4.cxx
index 88d2316..8df71b8 100644
--- a/vcl/source/gdi/outdev4.cxx
+++ b/vcl/source/gdi/outdev4.cxx
@@ -43,6 +43,7 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
#define HATCH_MAXPOINTS 1024
@@ -101,8 +102,8 @@ void OutputDevice::ImplDrawPolyPolygon( const PolyPolygon& rPolyPoly, const Poly
else if( pPolyPoly->Count() )
{
sal_uInt16 nCount = pPolyPoly->Count();
- sal_uInt32* pPointAry = new sal_uInt32[nCount];
- PCONSTSALPOINT* pPointAryAry = new PCONSTSALPOINT[nCount];
+ boost::scoped_array<sal_uInt32> pPointAry(new sal_uInt32[nCount]);
+ boost::scoped_array<PCONSTSALPOINT> pPointAryAry(new PCONSTSALPOINT[nCount]);
sal_uInt16 i = 0;
do
{
@@ -120,12 +121,9 @@ void OutputDevice::ImplDrawPolyPolygon( const PolyPolygon& rPolyPoly, const Poly
while( i < nCount );
if( nCount == 1 )
- mpGraphics->DrawPolygon( *pPointAry, *pPointAryAry, this );
+ mpGraphics->DrawPolygon( pPointAry[0], pPointAryAry[0], this );
else
- mpGraphics->DrawPolyPolygon( nCount, pPointAry, pPointAryAry, this );
-
- delete[] pPointAry;
- delete[] pPointAryAry;
+ mpGraphics->DrawPolyPolygon( nCount, pPointAry.get(), pPointAryAry.get(), this );
}
if( pClipPolyPoly )
@@ -1061,7 +1059,7 @@ void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHa
Rectangle aRect( rPolyPoly.GetBoundRect() );
const long nLogPixelWidth = ImplDevicePixelToLogicWidth( 1 );
const long nWidth = ImplDevicePixelToLogicWidth( std::max( ImplLogicWidthToDevicePixel( rHatch.GetDistance() ), 3L ) );
- Point* pPtBuffer = new Point[ HATCH_MAXPOINTS ];
+ boost::scoped_array<Point> pPtBuffer(new Point[ HATCH_MAXPOINTS ]);
Point aPt1, aPt2, aEndPt1;
Size aInc;
@@ -1070,7 +1068,7 @@ void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHa
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle(), aPt1, aPt2, aInc, aEndPt1 );
do
{
- ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf );
+ ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer.get(), bMtf );
aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height();
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height();
}
@@ -1082,7 +1080,7 @@ void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHa
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 900, aPt1, aPt2, aInc, aEndPt1 );
do
{
- ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf );
+ ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer.get(), bMtf );
aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height();
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height();
}
@@ -1094,15 +1092,13 @@ void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHa
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 450, aPt1, aPt2, aInc, aEndPt1 );
do
{
- ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf );
+ ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer.get(), bMtf );
aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height();
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height();
}
while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) );
}
}
-
- delete[] pPtBuffer;
}
}
}
More information about the Libreoffice-commits
mailing list