diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-03-21 19:16:11 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-03-21 19:17:27 +0900 |
commit | fc8b8033c645bb94484c51ddad4ed82add0cf6bc (patch) | |
tree | 88782a183e136d0074d8949a1331f858e2a9b756 /svl/source/items | |
parent | 5299cc26d136af179328f6e560040e1eabe8b9c8 (diff) |
Avoid possible resource leaks by boost::scoped_array
Change-Id: I4287fa05e35c132fb6e11d95dd17c3d3bf29defc
Diffstat (limited to 'svl/source/items')
-rw-r--r-- | svl/source/items/nranges.cxx | 24 | ||||
-rw-r--r-- | svl/source/items/poolio.cxx | 9 |
2 files changed, 16 insertions, 17 deletions
diff --git a/svl/source/items/nranges.cxx b/svl/source/items/nranges.cxx index c9fc72d51e93..13d58b02df57 100644 --- a/svl/source/items/nranges.cxx +++ b/svl/source/items/nranges.cxx @@ -20,7 +20,7 @@ #include <cassert> #include <vector> // compiled via include from itemset.cxx only! - +#include <boost/scoped_array.hpp> #ifdef DBG_UTIL @@ -436,9 +436,9 @@ SfxUShortRanges& SfxUShortRanges::operator -= // (size is computed for maximal possibly split-count plus terminating 0) sal_uInt16 nThisSize = Count_Impl(_pRanges); sal_uInt16 nTargetSize = 1 + ( nThisSize + Count_Impl(rRanges._pRanges) ); - sal_uInt16 *pTarget = new sal_uInt16[ nTargetSize ]; - memset( pTarget, 0, sizeof(sal_uInt16)*nTargetSize ); - memcpy( pTarget, _pRanges, sizeof(sal_uInt16)*nThisSize ); + boost::scoped_array<sal_uInt16> pTarget(new sal_uInt16[ nTargetSize ]); + memset( pTarget.get(), 0, sizeof(sal_uInt16)*nTargetSize ); + memcpy( pTarget.get(), _pRanges, sizeof(sal_uInt16)*nThisSize ); sal_uInt16 nPos1 = 0, nPos2 = 0, nTargetPos = 0; while( _pRanges[ nPos1 ] ) @@ -540,16 +540,15 @@ SfxUShortRanges& SfxUShortRanges::operator -= // assign the differentiated ranges delete[] _pRanges; - sal_uInt16 nUShorts = Count_Impl(pTarget) + 1; + sal_uInt16 nUShorts = Count_Impl(pTarget.get()) + 1; if ( 1 != nUShorts ) { _pRanges = new sal_uInt16[ nUShorts ]; - memcpy( _pRanges, pTarget, nUShorts * sizeof(sal_uInt16) ); + memcpy( _pRanges, pTarget.get(), nUShorts * sizeof(sal_uInt16) ); } else _pRanges = 0; - delete [] pTarget; return *this; } @@ -587,9 +586,9 @@ SfxUShortRanges& SfxUShortRanges::operator /= // (size is computed for maximal possibly split-count plus terminating 0) sal_uInt16 nThisSize = Count_Impl(_pRanges); sal_uInt16 nTargetSize = 1 + ( nThisSize + Count_Impl(rRanges._pRanges) ); - sal_uInt16 *pTarget = new sal_uInt16[ nTargetSize ]; - memset( pTarget, 0, sizeof(sal_uInt16)*nTargetSize ); - memcpy( pTarget, _pRanges, sizeof(sal_uInt16)*nThisSize ); + boost::scoped_array<sal_uInt16> pTarget(new sal_uInt16[ nTargetSize ]); + memset( pTarget.get(), 0, sizeof(sal_uInt16)*nTargetSize ); + memcpy( pTarget.get(), _pRanges, sizeof(sal_uInt16)*nThisSize ); sal_uInt16 nPos1 = 0, nPos2 = 0, nTargetPos = 0; while( _pRanges[ nPos1 ] != 0 && rRanges._pRanges[ nPos2 ] != 0 ) @@ -659,16 +658,15 @@ SfxUShortRanges& SfxUShortRanges::operator /= // assign the intersected ranges delete[] _pRanges; - sal_uInt16 nUShorts = Count_Impl(pTarget) + 1; + sal_uInt16 nUShorts = Count_Impl(pTarget.get()) + 1; if ( 1 != nUShorts ) { _pRanges = new sal_uInt16[ nUShorts ]; - memcpy( _pRanges, pTarget, nUShorts * sizeof(sal_uInt16) ); + memcpy( _pRanges, pTarget.get(), nUShorts * sizeof(sal_uInt16) ); } else _pRanges = 0; - delete [] pTarget; return *this; } diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx index 90d952ad76de..7f2dc56bd1a1 100644 --- a/svl/source/items/poolio.cxx +++ b/svl/source/items/poolio.cxx @@ -28,6 +28,7 @@ #include <svl/brdcst.hxx> #include <svl/filerec.hxx> #include "poolio.hxx" +#include <boost/scoped_array.hpp> // STATIC DATA ----------------------------------------------------------- @@ -762,10 +763,10 @@ SvStream &SfxItemPool::Load1_Impl(SvStream &rStream) CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_SIZES ); sal_uInt32 nSizeTableLen(0); rStream.ReadUInt32( nSizeTableLen ); - sal_Char *pBuf = new sal_Char[nSizeTableLen]; - rStream.Read( pBuf, nSizeTableLen ); + boost::scoped_array<sal_Char> pBuf(new sal_Char[nSizeTableLen]); + rStream.Read( pBuf.get(), nSizeTableLen ); sal_uLong nEndOfSizes = rStream.Tell(); - SvMemoryStream aSizeTable( pBuf, nSizeTableLen, STREAM_READ ); + SvMemoryStream aSizeTable( pBuf.get(), nSizeTableLen, STREAM_READ ); // ab Version 1.3 steht in der Size-Table eine Versions-Map if ( pImp->nMajorVer > 1 || pImp->nMinorVer >= 3 ) @@ -968,7 +969,7 @@ SvStream &SfxItemPool::Load1_Impl(SvStream &rStream) rStream.Seek( nPos + nSize ); } - delete[] pBuf; + pBuf.reset(); rStream.Seek(nEndOfSizes); CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL ); CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL ); |