diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-31 14:46:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-02-01 12:15:22 +0000 |
commit | 2489000d3fd66319a8355fd4e37cfdfda47296d0 (patch) | |
tree | caad79e7b5bec3863604b20190b682c0d73d2b25 /sd | |
parent | 595848c85acc2609fcc48a40c7a9f216a2722cd8 (diff) |
loplugin:useuniqueptr extend to check local vars
just the simple and obvious case for now, of a local var being allocated
and deleted inside a single local block, and the delete happening at the
end of the block
Change-Id: I3a7a094da543debdcd2374737c2ecff91d644625
Reviewed-on: https://gerrit.libreoffice.org/33749
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/filter/eppt/pptexsoundcollection.cxx | 7 | ||||
-rw-r--r-- | sd/source/filter/ppt/pptin.cxx | 8 | ||||
-rw-r--r-- | sd/source/filter/ppt/propread.cxx | 47 | ||||
-rw-r--r-- | sd/source/ui/docshell/docshel2.cxx | 5 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 8 |
5 files changed, 30 insertions, 45 deletions
diff --git a/sd/source/filter/eppt/pptexsoundcollection.cxx b/sd/source/filter/eppt/pptexsoundcollection.cxx index 2027ff3dd58c..24ee032c6ac6 100644 --- a/sd/source/filter/eppt/pptexsoundcollection.cxx +++ b/sd/source/filter/eppt/pptexsoundcollection.cxx @@ -129,16 +129,15 @@ void ExSoundEntry::Write( SvStream& rSt, sal_uInt32 nId ) const SvStream* pSourceFile = ::utl::UcbStreamHelper::CreateStream( aSoundURL, StreamMode::READ ); if ( pSourceFile ) { - sal_uInt8* pBuf = new sal_uInt8[ 0x10000 ]; // 64 kB Buffer + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ 0x10000 ] ); // 64 kB Buffer while ( nBytesLeft ) { sal_uInt32 nToDo = ( nBytesLeft > 0x10000 ) ? 0x10000 : nBytesLeft; - pSourceFile->ReadBytes(pBuf, nToDo); - rSt.WriteBytes(pBuf, nToDo); + pSourceFile->ReadBytes(pBuf.get(), nToDo); + rSt.WriteBytes(pBuf.get(), nToDo); nBytesLeft -= nToDo; } delete pSourceFile; - delete[] pBuf; } } catch( css::uno::Exception& ) diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx index 0679a1e7d61c..cb3283935a3e 100644 --- a/sd/source/filter/ppt/pptin.cxx +++ b/sd/source/filter/ppt/pptin.cxx @@ -1951,14 +1951,14 @@ OUString ImplSdPPTImport::ReadSound(sal_uInt32 nSoundRef) const aGalleryUserSound.Append( aRetval ); sal_uInt32 nSoundDataLen = aSoundDataRecHd.nRecLen; - sal_uInt8* pBuf = new sal_uInt8[ nSoundDataLen ]; + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ nSoundDataLen ] ); - rStCtrl.ReadBytes(pBuf, nSoundDataLen); + rStCtrl.ReadBytes(pBuf.get(), nSoundDataLen); SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aGalleryUserSound.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC ); if( pOStm ) { - pOStm->WriteBytes(pBuf, nSoundDataLen); + pOStm->WriteBytes(pBuf.get(), nSoundDataLen); if( pOStm->GetError() == ERRCODE_NONE ) { @@ -1968,8 +1968,6 @@ OUString ImplSdPPTImport::ReadSound(sal_uInt32 nSoundRef) const delete pOStm; } - - delete[] pBuf; } } } diff --git a/sd/source/filter/ppt/propread.cxx b/sd/source/filter/ppt/propread.cxx index 2167bda64e3e..d567b2c77855 100644 --- a/sd/source/filter/ppt/propread.cxx +++ b/sd/source/filter/ppt/propread.cxx @@ -104,13 +104,13 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) { try { - sal_Char* pString = new sal_Char[ nItemSize ]; + std::unique_ptr<sal_Char[]> pString( new sal_Char[ nItemSize ] ); if ( mnTextEnc == RTL_TEXTENCODING_UCS2 ) { nItemSize >>= 1; if ( nItemSize > 1 ) { - sal_Unicode* pWString = reinterpret_cast<sal_Unicode*>(pString); + sal_Unicode* pWString = reinterpret_cast<sal_Unicode*>(pString.get()); for (sal_uInt32 i = 0; i < nItemSize; ++i) ReadUtf16( pWString[ i ] ); rString = OUString(pWString, lcl_getMaxSafeStrLen(nItemSize)); @@ -121,17 +121,16 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) } else { - SvMemoryStream::ReadBytes(pString, nItemSize); + SvMemoryStream::ReadBytes(pString.get(), nItemSize); if ( pString[ nItemSize - 1 ] == 0 ) { if ( nItemSize > 1 ) - rString = OUString(pString, rtl_str_getLength(pString), mnTextEnc); + rString = OUString(pString.get(), rtl_str_getLength(pString.get()), mnTextEnc); else rString.clear(); bRetValue = true; } } - delete[] pString; } catch( const std::bad_alloc& ) { @@ -159,18 +158,17 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) { try { - sal_Unicode* pString = new sal_Unicode[ nItemSize ]; + std::unique_ptr<sal_Unicode[]> pString( new sal_Unicode[ nItemSize ] ); for (sal_uInt32 i = 0; i < nItemSize; ++i) ReadUtf16( pString[ i ] ); if ( pString[ nItemSize - 1 ] == 0 ) { if ( (sal_uInt16)nItemSize > 1 ) - rString = OUString(pString, lcl_getMaxSafeStrLen(nItemSize)); + rString = OUString(pString.get(), lcl_getMaxSafeStrLen(nItemSize)); else rString.clear(); bRetValue = true; } - delete[] pString; } catch( const std::bad_alloc& ) { @@ -298,18 +296,16 @@ void Section::GetDictionary(Dictionary& rDict) { if ( mnTextEnc == RTL_TEXTENCODING_UCS2 ) { - sal_Unicode* pWString = new sal_Unicode[nSize]; + std::unique_ptr<sal_Unicode[]> pWString( new sal_Unicode[nSize] ); for (sal_uInt32 j = 0; j < nSize; ++j) aStream.ReadUtf16(pWString[j]); - aString = OUString(pWString, lcl_getMaxSafeStrLen(nSize)); - delete[] pWString; + aString = OUString(pWString.get(), lcl_getMaxSafeStrLen(nSize)); } else { - sal_Char* pString = new sal_Char[nSize]; - aStream.ReadBytes(pString, nSize); - aString = OUString(pString, lcl_getMaxSafeStrLen(nSize), mnTextEnc); - delete[] pString; + std::unique_ptr<sal_Char[]> pString( new sal_Char[nSize] ); + aStream.ReadBytes(pString.get(), nSize); + aString = OUString(pString.get(), lcl_getMaxSafeStrLen(nSize), mnTextEnc); } } catch( const std::bad_alloc& ) @@ -456,10 +452,9 @@ void Section::Read( SotStorageStream *pStrm ) // make sure we don't overflow the section size if( nPropSize > nSecSize - nSecOfs ) nPropSize = nSecSize - nSecOfs; - sal_uInt8* pBuf = new sal_uInt8[ nPropSize ]; - nPropSize = pStrm->ReadBytes(pBuf, nPropSize); - AddProperty( nPropId, pBuf, nPropSize ); - delete[] pBuf; + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ nPropSize ] ); + nPropSize = pStrm->ReadBytes(pBuf.get(), nPropSize); + AddProperty( nPropId, pBuf.get(), nPropSize ); } if ( nPropId == 1 ) { @@ -517,10 +512,9 @@ void Section::Read( SotStorageStream *pStrm ) { break; } - sal_uInt8* pBuf = new sal_uInt8[ nSize ]; - nSize = pStrm->ReadBytes(pBuf, nSize); - AddProperty( 0xffffffff, pBuf, nSize ); - delete[] pBuf; + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ nSize ] ); + nSize = pStrm->ReadBytes(pBuf.get(), nSize); + AddProperty( 0xffffffff, pBuf.get(), nSize ); } pStrm->Seek(nCurrent); } @@ -581,7 +575,7 @@ void PropRead::Read() mpSvStream->ReadUInt16( mnByteOrder ).ReadUInt16( mnFormat ).ReadUInt16( mnVersionLo ).ReadUInt16( mnVersionHi ); if ( mnByteOrder == 0xfffe ) { - sal_uInt8* pSectCLSID = new sal_uInt8[ 16 ]; + std::unique_ptr<sal_uInt8[]> pSectCLSID( new sal_uInt8[ 16 ] ); mpSvStream->ReadBytes(mApplicationCLSID, 16); mpSvStream->ReadUInt32( nSections ); if ( nSections > 2 ) // sj: PowerPoint documents are containing max 2 sections @@ -590,16 +584,15 @@ void PropRead::Read() } else for ( sal_uInt32 i = 0; i < nSections; i++ ) { - mpSvStream->ReadBytes(pSectCLSID, 16); + mpSvStream->ReadBytes(pSectCLSID.get(), 16); mpSvStream->ReadUInt32( nSectionOfs ); nCurrent = mpSvStream->Tell(); mpSvStream->Seek( nSectionOfs ); - Section aSection( pSectCLSID ); + Section aSection( pSectCLSID.get() ); aSection.Read( mpSvStream.get() ); maSections.push_back( o3tl::make_unique<Section>( aSection ) ); mpSvStream->Seek( nCurrent ); } - delete[] pSectCLSID; } } } diff --git a/sd/source/ui/docshell/docshel2.cxx b/sd/source/ui/docshell/docshel2.cxx index af8320e8a531..f43bc1a71d2d 100644 --- a/sd/source/ui/docshell/docshel2.cxx +++ b/sd/source/ui/docshell/docshel2.cxx @@ -52,7 +52,7 @@ void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect) // THUMBNAIL: here we may can set the draft mode } - ClientView* pView = new ClientView(this, pOut); + std::unique_ptr<ClientView> pView( new ClientView(this, pOut) ); pView->SetHlplVisible(false); pView->SetGridVisible(false); @@ -116,9 +116,6 @@ void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect) pOut->SetMapMode(aOldMapMode); } } - - delete pView; - } Rectangle DrawDocShell::GetVisArea(sal_uInt16 nAspect) const diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 7fd6355ce508..082d6ec36389 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -1895,9 +1895,9 @@ void SAL_CALL SdXImpressDocument::render( sal_Int32 nRenderer, const uno::Any& r if ( !( (mpDoc->GetSdPage((sal_Int16) nPageNumber-1, PageKind::Standard))->IsExcluded() ) || (pPDFExtOutDevData && pPDFExtOutDevData->GetIsExportHiddenSlides()) ) { - ::sd::ClientView* pView = new ::sd::ClientView( mpDocShell, pOut ); - Rectangle aVisArea = Rectangle( Point(), mpDoc->GetSdPage( (sal_uInt16)nPageNumber - 1, ePageKind )->GetSize() ); - vcl::Region aRegion( aVisArea ); + std::unique_ptr<::sd::ClientView> pView( new ::sd::ClientView( mpDocShell, pOut ) ); + Rectangle aVisArea = Rectangle( Point(), mpDoc->GetSdPage( (sal_uInt16)nPageNumber - 1, ePageKind )->GetSize() ); + vcl::Region aRegion( aVisArea ); ::sd::ViewShell* pOldViewSh = mpDocShell->GetViewShell(); ::sd::View* pOldSdView = pOldViewSh ? pOldViewSh->GetView() : nullptr; @@ -2207,8 +2207,6 @@ void SAL_CALL SdXImpressDocument::render( sal_Int32 nRenderer, const uno::Any& r pView->DrawMarkedObj(*pOut); } } - - delete pView; } } } |