filter/source/graphicfilter/ipict/ipict.cxx | 6 +- filter/source/graphicfilter/ipsd/ipsd.cxx | 4 - filter/source/msfilter/escherex.cxx | 16 +++---- filter/source/msfilter/msdffimp.cxx | 23 ++++------ filter/source/msfilter/svdfppt.cxx | 60 ++++++++++++---------------- 5 files changed, 48 insertions(+), 61 deletions(-)
New commits: commit 22f7c87dbdc5a6157012fcb2c0ed60fe4e022509 Author: Takeshi Abe <t...@fixedpoint.jp> Date: Wed Apr 9 16:35:52 2014 +0900 Avoid possible memory leaks in case of exceptions Change-Id: I288c77190a8205ba320bb788a52f3b2ef9d2557f diff --git a/filter/source/graphicfilter/ipict/ipict.cxx b/filter/source/graphicfilter/ipict/ipict.cxx index acf4b02..0292f0a 100644 --- a/filter/source/graphicfilter/ipict/ipict.cxx +++ b/filter/source/graphicfilter/ipict/ipict.cxx @@ -27,6 +27,7 @@ #include <math.h> #include "shape.hxx" +#include <boost/scoped_array.hpp> class FilterConfigItem; @@ -1007,7 +1008,7 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, sal_Bool bBaseAddr, sal_Bo { if ( ( nCmpCount == 3 ) || ( nCmpCount == 4 ) ) { - sal_uInt8* pScanline = new sal_uInt8[ nWidth * nCmpCount ]; + boost::scoped_array<sal_uInt8> pScanline(new sal_uInt8[ nWidth * nCmpCount ]); for ( ny = 0; ny < nHeight; ny++ ) { nSrcBitsPos = pPict->Tell(); @@ -1047,7 +1048,7 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, sal_Bool bBaseAddr, sal_Bo pScanline[ i++ ] = nDat; } } - sal_uInt8* pTmp = pScanline; + sal_uInt8* pTmp = pScanline.get(); if ( nCmpCount == 4 ) pTmp += nWidth; for ( nx = 0; nx < nWidth; pTmp++ ) @@ -1055,7 +1056,6 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, sal_Bool bBaseAddr, sal_Bo nDataSize += (sal_uLong)nByteCount; pPict->Seek( nSrcBitsPos + (sal_uLong)nByteCount ); } - delete[] pScanline; } } } diff --git a/filter/source/graphicfilter/ipsd/ipsd.cxx b/filter/source/graphicfilter/ipsd/ipsd.cxx index 1dbe3cb..45b923c 100644 --- a/filter/source/graphicfilter/ipsd/ipsd.cxx +++ b/filter/source/graphicfilter/ipsd/ipsd.cxx @@ -21,6 +21,7 @@ #include <vcl/graph.hxx> #include <vcl/bmpacc.hxx> #include <vcl/outdev.hxx> +#include <boost/scoped_array.hpp> class FilterConfigItem; @@ -577,7 +578,7 @@ sal_Bool PSDReader::ImplReadBody() if ( mpFileHeader->nMode == PSD_CMYK ) { sal_uInt32 nBlack, nBlackMax = 0; - sal_uInt8* pBlack = new sal_uInt8[ mpFileHeader->nRows * mpFileHeader->nColumns ]; + boost::scoped_array<sal_uInt8> pBlack(new sal_uInt8[ mpFileHeader->nRows * mpFileHeader->nColumns ]); nY = 0; while ( nY < mpFileHeader->nRows ) { @@ -654,7 +655,6 @@ sal_Bool PSDReader::ImplReadBody() mpWriteAcc->SetPixel( nY, nX, BitmapColor( cR, cG, cB ) ); } } - delete[] pBlack; } } break; diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx index 370c06e..8989233 100644 --- a/filter/source/msfilter/escherex.cxx +++ b/filter/source/msfilter/escherex.cxx @@ -90,6 +90,7 @@ #include <vcl/virdev.hxx> #include <rtl/crc.h> #include <rtl/strbuf.hxx> +#include <boost/scoped_array.hpp> using namespace ::rtl; using namespace ::com::sun::star; @@ -4260,7 +4261,7 @@ void EscherGraphicProvider::WriteBlibStoreContainer( SvStream& rSt, SvStream* pM { sal_uInt32 i, nBlipSize, nOldPos = pMergePicStreamBSE->Tell(); const sal_uInt32 nBuf = 0x40000; // 256KB buffer - sal_uInt8* pBuf = new sal_uInt8[ nBuf ]; + boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ nBuf ]); for ( i = 0; i < mnBlibEntrys; i++ ) { @@ -4290,12 +4291,11 @@ void EscherGraphicProvider::WriteBlibStoreContainer( SvStream& rSt, SvStream* pM while ( nBlipSize ) { sal_uInt32 nBytes = ( nBlipSize > nBuf ? nBuf : nBlipSize ); - pMergePicStreamBSE->Read( pBuf, nBytes ); - rSt.Write( pBuf, nBytes ); + pMergePicStreamBSE->Read( pBuf.get(), nBytes ); + rSt.Write( pBuf.get(), nBytes ); nBlipSize -= nBytes; } } - delete[] pBuf; pMergePicStreamBSE->Seek( nOldPos ); } else @@ -5134,7 +5134,6 @@ void EscherEx::Flush( SvStream* pPicStreamMergeBSE /* = NULL */ ) void EscherEx::InsertAtCurrentPos( sal_uInt32 nBytes, bool bExpandEndOfAtom ) { sal_uInt32 nSize, nType, nSource, nBufSize, nToCopy, nCurPos = mpOutStrm->Tell(); - sal_uInt8* pBuf; // adjust persist table for( size_t i = 0, n = maPersistTable.size(); i < n; ++i ) { @@ -5173,18 +5172,17 @@ void EscherEx::InsertAtCurrentPos( sal_uInt32 nBytes, bool bExpandEndOfAtom ) mpOutStrm->Seek( STREAM_SEEK_TO_END ); nSource = mpOutStrm->Tell(); nToCopy = nSource - nCurPos; // increase the size of the tream by nBytes - pBuf = new sal_uInt8[ 0x40000 ]; // 256KB Buffer + boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ 0x40000 ]); // 256KB Buffer while ( nToCopy ) { nBufSize = ( nToCopy >= 0x40000 ) ? 0x40000 : nToCopy; nToCopy -= nBufSize; nSource -= nBufSize; mpOutStrm->Seek( nSource ); - mpOutStrm->Read( pBuf, nBufSize ); + mpOutStrm->Read( pBuf.get(), nBufSize ); mpOutStrm->Seek( nSource + nBytes ); - mpOutStrm->Write( pBuf, nBufSize ); + mpOutStrm->Write( pBuf.get(), nBufSize ); } - delete[] pBuf; mpOutStrm->Seek( nCurPos ); } diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 2fe9e63..2622b0fd 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -6360,11 +6360,10 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, Rect sal_Int32 nDbgLen = nLength - nSkip; if ( nDbgLen ) { - sal_Char* pDat = new sal_Char[ nDbgLen ]; - pGrStream->Read( pDat, nDbgLen ); - pDbgOut->Write( pDat, nDbgLen ); + boost::scoped_array<sal_Char> pDat(new sal_Char[ nDbgLen ]); + pGrStream->Read( pDat.get(), nDbgLen ); + pDbgOut->Write( pDat.get(), nDbgLen ); pGrStream->SeekRel( -nDbgLen ); - delete[] pDat; } } @@ -6658,7 +6657,6 @@ bool SvxMSDffManager::ConvertToOle2( SvStream& rStm, sal_uInt32 nReadLen, sal_uInt32 nDummy0; sal_uInt32 nDummy1; sal_uInt32 nDataLen; - sal_uInt8 * pData; sal_uInt32 nBytesRead = 0; do { @@ -6669,10 +6667,9 @@ bool SvxMSDffManager::ConvertToOle2( SvStream& rStm, sal_uInt32 nReadLen, { if( 0x10000L > nStrLen ) { - sal_Char * pBuf = new sal_Char[ nStrLen ]; - rStm.Read( pBuf, nStrLen ); - aSvrName = OUString( pBuf, (sal_uInt16) nStrLen-1, osl_getThreadTextEncoding() ); - delete[] pBuf; + boost::scoped_array<sal_Char> pBuf(new sal_Char[ nStrLen ]); + rStm.Read( pBuf.get(), nStrLen ); + aSvrName = OUString( pBuf.get(), (sal_uInt16) nStrLen-1, osl_getThreadTextEncoding() ); } else break; @@ -6687,15 +6684,15 @@ bool SvxMSDffManager::ConvertToOle2( SvStream& rStm, sal_uInt32 nReadLen, { if( xOle10Stm.Is() ) { - pData = new sal_uInt8[ nDataLen ]; + boost::scoped_array<sal_uInt8> pData(new sal_uInt8[ nDataLen ]); if( !pData ) return false; - rStm.Read( pData, nDataLen ); + rStm.Read( pData.get(), nDataLen ); // write to ole10 stream xOle10Stm->WriteUInt32( nDataLen ); - xOle10Stm->Write( pData, nDataLen ); + xOle10Stm->Write( pData.get(), nDataLen ); xOle10Stm = SotStorageStreamRef(); // set the compobj stream @@ -6718,8 +6715,6 @@ bool SvxMSDffManager::ConvertToOle2( SvStream& rStm, sal_uInt32 nReadLen, sal_uLong nCbFmt = SotExchange::RegisterFormatName( aSvrName ); rDest->SetClass( SvGlobalName(), nCbFmt, aSvrName ); } - - delete[] pData; } else if( nRecType == 5 && !pMtf ) { diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx index 06d6faf..c176c6d 100644 --- a/filter/source/msfilter/svdfppt.cxx +++ b/filter/source/msfilter/svdfppt.cxx @@ -119,6 +119,7 @@ #include <set> #include <rtl/strbuf.hxx> #include <tools/time.hxx> +#include <boost/scoped_array.hpp> // PPT ColorScheme Slots #define PPT_COLSCHEME (0x08000000) @@ -671,8 +672,8 @@ void SdrEscherImport::RecolorGraphic( SvStream& rSt, sal_uInt32 nRecLen, Graphic } if ( nGlobalColorsChanged || nFillColorsChanged ) { - Color* pSearchColors = new Color[ nGlobalColorsChanged ]; - Color* pReplaceColors = new Color[ nGlobalColorsChanged ]; + boost::scoped_array<Color> pSearchColors(new Color[ nGlobalColorsChanged ]); + boost::scoped_array<Color> pReplaceColors(new Color[ nGlobalColorsChanged ]); for ( j = 0; j < nGlobalColorsChanged; j++ ) { @@ -688,12 +689,9 @@ void SdrEscherImport::RecolorGraphic( SvStream& rSt, sal_uInt32 nRecLen, Graphic pReplaceColors[ j ].SetBlue( (sal_uInt8)( nReplace >> 16 ) ); } GDIMetaFile aGdiMetaFile( rGraphic.GetGDIMetaFile() ); - aGdiMetaFile.ReplaceColors( pSearchColors, pReplaceColors, + aGdiMetaFile.ReplaceColors( pSearchColors.get(), pReplaceColors.get(), nGlobalColorsChanged, NULL ); rGraphic = aGdiMetaFile; - - delete[] pSearchColors; - delete[] pReplaceColors; } } } @@ -1738,14 +1736,13 @@ const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& bool SdrPowerPointOLEDecompress( SvStream& rOutput, SvStream& rInput, sal_uInt32 nInputSize ) { sal_uInt32 nOldPos = rInput.Tell(); - char* pBuf = new char[ nInputSize ]; - rInput.Read( pBuf, nInputSize ); + boost::scoped_array<char> pBuf(new char[ nInputSize ]); + rInput.Read( pBuf.get(), nInputSize ); ZCodec aZCodec( 0x8000, 0x8000 ); aZCodec.BeginCompression(); - SvMemoryStream aSource( pBuf, nInputSize, STREAM_READ ); + SvMemoryStream aSource( pBuf.get(), nInputSize, STREAM_READ ); aZCodec.Decompress( aSource, rOutput ); const bool bSuccess(0L != aZCodec.EndCompression()); - delete[] pBuf; rInput.Seek( nOldPos ); return bSuccess; } @@ -2030,17 +2027,16 @@ void SdrPowerPointImport::SeekOle( SfxObjectShell* pShell, sal_uInt32 nFilterOpt sal_uInt32 nToCopy, nBufSize; nToCopy = pHd->nRecLen; - sal_uInt8* pBuf = new sal_uInt8[ 0x40000 ]; // 256KB Buffer + boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ 0x40000 ]); // 256KB Buffer if ( pBuf ) { while ( nToCopy ) { nBufSize = ( nToCopy >= 0x40000 ) ? 0x40000 : nToCopy; - rStCtrl.Read( pBuf, nBufSize ); - xOriginal->Write( pBuf, nBufSize ); + rStCtrl.Read( pBuf.get(), nBufSize ); + xOriginal->Write( pBuf.get(), nBufSize ); nToCopy -= nBufSize; } - delete[] pBuf; } } } @@ -2214,7 +2210,7 @@ SdrObject* SdrPowerPointImport::ApplyTextObj( PPTTextObj* pTextObj, SdrTextObj* if ( ! ( nTextSize & 0xffff0000 ) ) { PPTPortionObj* pPortion; - sal_Unicode* pParaText = new sal_Unicode[ nTextSize ]; + boost::scoped_array<sal_Unicode> pParaText(new sal_Unicode[ nTextSize ]); sal_Int32 nCurrentIndex = 0; for ( pPortion = pPara->First(); pPortion; pPortion = pPara->Next() ) { @@ -2224,7 +2220,7 @@ SdrObject* SdrPowerPointImport::ApplyTextObj( PPTTextObj* pTextObj, SdrTextObj* { sal_Int32 nCharacters = pPortion->Count(); const sal_Unicode* pSource = pPortion->maString.getStr(); - sal_Unicode* pDest = pParaText + nCurrentIndex; + sal_Unicode* pDest = pParaText.get() + nCurrentIndex; sal_uInt32 nFont; pPortion->GetAttrib( PPT_CharAttr_Font, nFont, pTextObj->GetInstance() ); @@ -2250,7 +2246,7 @@ SdrObject* SdrPowerPointImport::ApplyTextObj( PPTTextObj* pTextObj, SdrTextObj* ESelection aSelection( nParaIndex, 0, nParaIndex, 0 ); rOutliner.Insert( OUString(), nParaIndex, pPara->pParaSet->mnDepth ); - rOutliner.QuickInsertText( OUString(pParaText, nCurrentIndex), aSelection ); + rOutliner.QuickInsertText( OUString(pParaText.get(), nCurrentIndex), aSelection ); rOutliner.SetParaAttribs( nParaIndex, rOutliner.GetEmptyItemSet() ); if ( pS ) rOutliner.SetStyleSheet( nParaIndex, pS ); @@ -2309,7 +2305,6 @@ SdrObject* SdrPowerPointImport::ApplyTextObj( PPTTextObj* pTextObj, SdrTextObj* } aSelection.nStartPos = 0; rOutliner.QuickSetAttribs( aParagraphAttribs, aSelection ); - delete[] pParaText; } } OutlinerParaObject* pNewText = rOutliner.CreateParaObject(); @@ -5071,11 +5066,12 @@ void PPTStyleTextPropReader::Init( SvStream& rIn, SdrPowerPointImport& rMan, con if( aTextHd.nRecType == PPT_PST_TextCharsAtom ) { sal_uInt32 i; - sal_Unicode nChar,*pBuf = new sal_Unicode[ ( nMaxLen >> 1 ) + 1 ]; - rIn.Read( pBuf, nMaxLen ); + sal_Unicode nChar; + boost::scoped_array<sal_Unicode> pBuf(new sal_Unicode[ ( nMaxLen >> 1 ) + 1 ]); + rIn.Read( pBuf.get(), nMaxLen ); nMaxLen >>= 1; pBuf[ nMaxLen ] = 0; - sal_Unicode* pPtr = pBuf; + sal_Unicode* pPtr = pBuf.get(); #ifdef OSL_BIGENDIAN sal_Unicode nTemp; for ( i = 0; i < nMaxLen; i++ ) @@ -5083,7 +5079,7 @@ void PPTStyleTextPropReader::Init( SvStream& rIn, SdrPowerPointImport& rMan, con nTemp = *pPtr; *pPtr++ = ( nTemp << 8 ) | ( nTemp >> 8 ); } - pPtr = pBuf; + pPtr = pBuf.get(); #endif for ( i = 0; i < nMaxLen; pPtr++, i++ ) @@ -5102,15 +5098,14 @@ void PPTStyleTextPropReader::Init( SvStream& rIn, SdrPowerPointImport& rMan, con } } if ( i ) - aString = OUString(pBuf, i); - delete[] pBuf; + aString = OUString(pBuf.get(), i); } else if( aTextHd.nRecType == PPT_PST_TextBytesAtom ) { - sal_Char *pBuf = new sal_Char[ nMaxLen + 1 ]; + boost::scoped_array<sal_Char> pBuf(new sal_Char[ nMaxLen + 1 ]); pBuf[ nMaxLen ] = 0; - rIn.Read( pBuf, nMaxLen ); - sal_Char* pPtr = pBuf; + rIn.Read( pBuf.get(), nMaxLen ); + sal_Char* pPtr = pBuf.get(); for (;;) { sal_Char cLo = *pPtr; @@ -5121,14 +5116,13 @@ void PPTStyleTextPropReader::Init( SvStream& rIn, SdrPowerPointImport& rMan, con if ( nInstance == TSS_TYPE_PAGETITLE ) *pPtr = 0xb; else - aSpecMarkerList.push_back( (sal_uInt32)( (pPtr - pBuf) | PPT_SPEC_NEWLINE ) ); + aSpecMarkerList.push_back( (sal_uInt32)( (pPtr - pBuf.get()) | PPT_SPEC_NEWLINE ) ); } pPtr++; } - sal_Int32 nLen = pPtr - pBuf; + sal_Int32 nLen = pPtr - pBuf.get(); if ( nLen ) - aString = OUString( pBuf, nLen, RTL_TEXTENCODING_MS_1252 ); - delete[] pBuf; + aString = OUString( pBuf.get(), nLen, RTL_TEXTENCODING_MS_1252 ); } else { @@ -7455,7 +7449,7 @@ SdrObject* SdrPowerPointImport::CreateTable( SdrObject* pGroup, sal_uInt32* pTab CreateTableColumns( xTable->getColumns(), aColumns, pGroup->GetSnapRect().Right() ); sal_Int32 nCellCount = aRows.size() * aColumns.size(); - sal_Int32 *pMergedCellIndexTable = new sal_Int32[ nCellCount ]; + boost::scoped_array<sal_Int32> pMergedCellIndexTable(new sal_Int32[ nCellCount ]); for ( sal_Int32 i = 0; i < nCellCount; i++ ) pMergedCellIndexTable[ i ] = i; @@ -7520,7 +7514,7 @@ SdrObject* SdrPowerPointImport::CreateTable( SdrObject* pGroup, sal_uInt32* pTab ApplyCellLineAttributes( pObj, xTable, vPositions, aColumns.size() ); } } - delete[] pMergedCellIndexTable; + pMergedCellIndexTable.reset(); // we are replacing the whole group object by a single table object, so // possibly connections to the group object have to be removed. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits