summaryrefslogtreecommitdiff
path: root/filter/source/flash
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-05 23:56:45 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-05 23:57:32 +0900
commitbe8f375039e854775bbb4e03b68d444a9b157e95 (patch)
treef29d0a0729b0ad9c64677968bab4e98f4880f034 /filter/source/flash
parent0a215b9a980e68f899ad548f780bbe5a1fec8732 (diff)
Avoid possible resource leaks in case of exceptions
Change-Id: I6f1f6669b222f03ad220f01cae2e09d03550a58b
Diffstat (limited to 'filter/source/flash')
-rw-r--r--filter/source/flash/swfwriter1.cxx31
1 files changed, 14 insertions, 17 deletions
diff --git a/filter/source/flash/swfwriter1.cxx b/filter/source/flash/swfwriter1.cxx
index 4a67720b8a65..25b1fb566df5 100644
--- a/filter/source/flash/swfwriter1.cxx
+++ b/filter/source/flash/swfwriter1.cxx
@@ -36,6 +36,7 @@
#include <vcl/salbtype.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <boost/scoped_array.hpp>
using namespace ::swf;
using namespace ::std;
@@ -528,21 +529,20 @@ void Writer::Impl_writeText( const Point& rPos, const OUString& rText, const sal
else
{
Size aNormSize;
- sal_Int32* pOwnArray;
+ boost::scoped_array<sal_Int32> pOwnArray;
sal_Int32* pDX;
// get text sizes
if( pDXArray )
{
- pOwnArray = NULL;
aNormSize = Size( mpVDev->GetTextWidth( rText ), 0 );
pDX = (sal_Int32*) pDXArray;
}
else
{
- pOwnArray = new sal_Int32[ nLen ];
- aNormSize = Size( mpVDev->GetTextArray( rText, pOwnArray ), 0 );
- pDX = pOwnArray;
+ pOwnArray.reset(new sal_Int32[ nLen ]);
+ aNormSize = Size( mpVDev->GetTextArray( rText, pOwnArray.get() ), 0 );
+ pDX = pOwnArray.get();
}
if( nLen > 1 )
@@ -720,7 +720,6 @@ void Writer::Impl_writeText( const Point& rPos, const OUString& rText, const sal
}
mpVDev->SetFont( aOldFont );
- delete[] pOwnArray;
}
}
@@ -816,33 +815,33 @@ sal_uInt16 Writer::defineBitmap( const BitmapEx &bmpSource, sal_Int32 nJPEGQuali
getBitmapData( bmpSource, pImageData, pAlphaData, width, height );
sal_uInt32 raw_size = width * height * 4;
uLongf compressed_size = raw_size + (sal_uInt32)(raw_size/100) + 12;
- sal_uInt8 *pCompressed = new sal_uInt8[ compressed_size ];
+ boost::scoped_array<sal_uInt8> pCompressed(new sal_uInt8[ compressed_size ]);
#ifdef DBG_UTIL
- if(compress2(pCompressed, &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION) != Z_OK)
+ if(compress2(pCompressed.get(), &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION) != Z_OK)
{
DBG_ASSERT( false, "compress2 failed!" ); ((void)0);
}
#else
- compress2(pCompressed, &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION);
+ compress2(pCompressed.get(), &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION);
#endif
// AS: SWF files let you provide an Alpha mask for JPEG images, but we have
// to ZLIB compress the alpha channel separately.
uLong alpha_compressed_size = 0;
- sal_uInt8 *pAlphaCompressed = NULL;
+ boost::scoped_array<sal_uInt8> pAlphaCompressed;
if (bmpSource.IsAlpha() || bmpSource.IsTransparent())
{
alpha_compressed_size = uLongf(width * height + (sal_uInt32)(raw_size/100) + 12);
- pAlphaCompressed = new sal_uInt8[ compressed_size ];
+ pAlphaCompressed.reset(new sal_uInt8[ compressed_size ]);
#ifdef DBG_UTIL
- if(compress2(pAlphaCompressed, &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION) != Z_OK)
+ if(compress2(pAlphaCompressed.get(), &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION) != Z_OK)
{
DBG_ASSERT( false, "compress2 failed!" ); ((void)0);
}
#else
- compress2(pAlphaCompressed, &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION);
+ compress2(pAlphaCompressed.get(), &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION);
#endif
}
@@ -873,12 +872,10 @@ sal_uInt16 Writer::defineBitmap( const BitmapEx &bmpSource, sal_Int32 nJPEGQuali
// we have to export as TAG_DEFINEBITSJPEG3 in the case that there is alpha
// channel data.
if ( pJpgData && ( nJpgDataLength + alpha_compressed_size < compressed_size) )
- Impl_writeJPEG(nBitmapId, pJpgData, nJpgDataLength, pAlphaCompressed, alpha_compressed_size );
+ Impl_writeJPEG(nBitmapId, pJpgData, nJpgDataLength, pAlphaCompressed.get(), alpha_compressed_size );
else
- Impl_writeBmp( nBitmapId, width, height, pCompressed, compressed_size );
+ Impl_writeBmp( nBitmapId, width, height, pCompressed.get(), compressed_size );
- delete[] pCompressed;
- delete[] pAlphaCompressed;
delete[] pImageData;
delete[] pAlphaData;