diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-29 14:26:48 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-02 11:53:17 +0100 |
commit | e04f01abca1b7bc2cf8d643628a9dd31d476897f (patch) | |
tree | d978a72e9a83d2704b0d4609ad1588b4cf718938 /sot/source | |
parent | 97d14951adbcecf1257ce091b8c9de210b3a93cc (diff) |
loplugin:useuniqueptr in sot
Change-Id: If4d093079e13cfaebb9d226e39581b0c66e82786
Reviewed-on: https://gerrit.libreoffice.org/62651
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sot/source')
-rw-r--r-- | sot/source/sdstor/stg.cxx | 16 | ||||
-rw-r--r-- | sot/source/sdstor/stgdir.cxx | 37 | ||||
-rw-r--r-- | sot/source/sdstor/stgio.cxx | 8 | ||||
-rw-r--r-- | sot/source/sdstor/stgstrms.cxx | 5 |
4 files changed, 27 insertions, 39 deletions
diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx index 60147cd319ee..169c7cb84138 100644 --- a/sot/source/sdstor/stg.cxx +++ b/sot/source/sdstor/stg.cxx @@ -673,8 +673,8 @@ bool Storage::CopyTo( const OUString& rElem, BaseStorage* pDest, const OUString& if( pElem->m_aEntry.GetType() == STG_STORAGE ) { // copy the entire storage - BaseStorage* p1 = OpenStorage( rElem, INTERNAL_MODE ); - BaseStorage* p2 = pDest->OpenOLEStorage( rNew, StreamMode::WRITE | StreamMode::SHARE_DENYALL, pEntry->m_bDirect ); + tools::SvRef<BaseStorage> p1 = OpenStorage( rElem, INTERNAL_MODE ); + tools::SvRef<BaseStorage> p2 = pDest->OpenOLEStorage( rNew, StreamMode::WRITE | StreamMode::SHARE_DENYALL, pEntry->m_bDirect ); if ( p2 ) { @@ -682,7 +682,7 @@ bool Storage::CopyTo( const OUString& rElem, BaseStorage* pDest, const OUString& if( !nTmpErr ) { p2->SetClassId( p1->GetClassId() ); - p1->CopyTo( p2 ); + p1->CopyTo( p2.get() ); SetError( p1->GetError() ); nTmpErr = p2->GetError(); @@ -695,22 +695,20 @@ bool Storage::CopyTo( const OUString& rElem, BaseStorage* pDest, const OUString& pDest->SetError( nTmpErr ); } - delete p1; - delete p2; return Good() && pDest->Good(); } else { // stream copy - BaseStorageStream* p1 = OpenStream( rElem, INTERNAL_MODE ); - BaseStorageStream* p2 = pDest->OpenStream( rNew, StreamMode::WRITE | StreamMode::SHARE_DENYALL, pEntry->m_bDirect ); + tools::SvRef<BaseStorageStream> p1 = OpenStream( rElem, INTERNAL_MODE ); + tools::SvRef<BaseStorageStream> p2 = pDest->OpenStream( rNew, StreamMode::WRITE | StreamMode::SHARE_DENYALL, pEntry->m_bDirect ); if ( p2 ) { ErrCode nTmpErr = p2->GetError(); if( !nTmpErr ) { - p1->CopyTo( p2 ); + p1->CopyTo( p2.get() ); SetError( p1->GetError() ); nTmpErr = p2->GetError(); @@ -723,8 +721,6 @@ bool Storage::CopyTo( const OUString& rElem, BaseStorage* pDest, const OUString& pDest->SetError( nTmpErr ); } - delete p1; - delete p2; return Good() && pDest->Good(); } } diff --git a/sot/source/sdstor/stgdir.cxx b/sot/source/sdstor/stgdir.cxx index da729a9031ef..6f52a38475d6 100644 --- a/sot/source/sdstor/stgdir.cxx +++ b/sot/source/sdstor/stgdir.cxx @@ -626,13 +626,13 @@ bool StgDirEntry::Tmp2Strm() if ( !m_pStgStrm ) return false; sal_uInt64 n = m_pTmpStrm->GetSize(); - StgStrm* pNewStrm; + std::unique_ptr<StgStrm> pNewStrm; StgIo& rIo = m_pStgStrm->GetIo(); sal_uLong nThreshold = static_cast<sal_uLong>(rIo.m_aHdr.GetThreshold()); if( n < nThreshold ) - pNewStrm = new StgSmallStrm( rIo, STG_EOF ); + pNewStrm.reset(new StgSmallStrm( rIo, STG_EOF )); else - pNewStrm = new StgDataStrm( rIo, STG_EOF ); + pNewStrm.reset(new StgDataStrm( rIo, STG_EOF )); if( pNewStrm->SetSize( n ) ) { sal_uInt8 p[ 4096 ]; @@ -652,16 +652,16 @@ bool StgDirEntry::Tmp2Strm() { m_pTmpStrm->Seek( m_nPos ); m_pStgStrm->GetIo().SetError( m_pTmpStrm->GetError() ); - delete pNewStrm; return false; } else { m_pStgStrm->SetSize( 0 ); delete m_pStgStrm; - m_pStgStrm = pNewStrm; + m_pStgStrm = pNewStrm.get(); pNewStrm->SetEntry( *this ); pNewStrm->Pos2Page( m_nPos ); + pNewStrm.release(); delete m_pTmpStrm; delete m_pCurStrm; m_pTmpStrm = m_pCurStrm = nullptr; @@ -741,11 +741,10 @@ void StgDirStrm::SetupEntry( sal_Int32 n, StgDirEntry* pUpper ) sal_uInt64 nUnderlyingStreamSize = pUnderlyingStream->TellEnd(); bool bOk(false); - StgDirEntry* pCur = new StgDirEntry( p, STGENTRY_SIZE, nUnderlyingStreamSize, &bOk ); + std::unique_ptr<StgDirEntry> pCur(new StgDirEntry( p, STGENTRY_SIZE, nUnderlyingStreamSize, &bOk )); if( !bOk ) { - delete pCur; m_rIo.SetError( SVSTREAM_GENERALERROR ); // an error occurred return; @@ -764,7 +763,6 @@ void StgDirStrm::SetupEntry( sal_Int32 n, StgDirEntry* pUpper ) nLeaf = pCur->m_aEntry.GetLeaf( STG_CHILD ); if (nLeaf != STG_FREE && nLeaf == n) { - delete pCur; m_rIo.SetError( SVSTREAM_GENERALERROR ); return; } @@ -779,14 +777,13 @@ void StgDirStrm::SetupEntry( sal_Int32 n, StgDirEntry* pUpper ) if (pUp->m_aEntry.GetLeaf(STG_CHILD) == nLeaf) { SAL_WARN("sot", "Leaf node of upper StgDirEntry is same as current StgDirEntry's leaf node. Circular entry chain, discarding link"); - delete pCur; return; } pUp = pUp->m_pUp; } if( StgAvlNode::Insert - ( reinterpret_cast<StgAvlNode**>( pUpper ? &pUpper->m_pDown : &m_pRoot ), pCur ) ) + ( reinterpret_cast<StgAvlNode**>( pUpper ? &pUpper->m_pDown : &m_pRoot ), pCur.get() ) ) { pCur->m_pUp = pUpper; } @@ -796,16 +793,11 @@ void StgDirStrm::SetupEntry( sal_Int32 n, StgDirEntry* pUpper ) // that contain duplicate entries in 'Directory' section // so don't set the error flag here and just skip those // (was: rIo.SetError( SVSTREAM_CANNOT_MAKE );) - delete pCur; return; } SetupEntry( nLeft, pUpper ); SetupEntry( nRight, pUpper ); - SetupEntry( nLeaf, pCur ); - } - else - { - delete pCur; + SetupEntry( nLeaf, pCur.release() ); } } } @@ -928,22 +920,23 @@ StgDirEntry* StgDirStrm::Create( StgDirEntry& rStg, const OUString& rName, StgEn pRes->m_bRemoved = pRes->m_bTemp = false; pRes->m_bDirty = true; + return pRes; } else { - pRes = new StgDirEntry( aEntry ); - if( StgAvlNode::Insert( reinterpret_cast<StgAvlNode**>(&rStg.m_pDown), pRes ) ) + std::unique_ptr<StgDirEntry> pNewRes(new StgDirEntry( aEntry )); + if( StgAvlNode::Insert( reinterpret_cast<StgAvlNode**>(&rStg.m_pDown), pNewRes.get() ) ) { - pRes->m_pUp = &rStg; - pRes->m_bDirty = true; + pNewRes->m_pUp = &rStg; + pNewRes->m_bDirty = true; } else { m_rIo.SetError( SVSTREAM_CANNOT_MAKE ); - delete pRes; pRes = nullptr; + pNewRes.reset(); } + return pNewRes.release(); } - return pRes; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sot/source/sdstor/stgio.cxx b/sot/source/sdstor/stgio.cxx index 803ab3761b68..e41c3d356ce4 100644 --- a/sot/source/sdstor/stgio.cxx +++ b/sot/source/sdstor/stgio.cxx @@ -371,9 +371,9 @@ FatError StgIo::ValidateFATs() { if( m_bFile ) { - Validator *pV = new Validator( *this ); + std::unique_ptr<Validator> pV(new Validator( *this )); bool bRet1 = !pV->IsError(), bRet2 = true ; - delete pV; + pV.reset(); SvFileStream *pFileStrm = static_cast<SvFileStream *>( GetStrm() ); if ( !pFileStrm ) @@ -384,9 +384,9 @@ FatError StgIo::ValidateFATs() StreamMode::READ | StreamMode::SHARE_DENYNONE) && aIo.Load() ) { - pV = new Validator( aIo ); + pV.reset(new Validator( aIo )); bRet2 = !pV->IsError(); - delete pV; + pV.reset(); } FatError nErr; diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx index 9efd318be758..a03b75ccbe42 100644 --- a/sot/source/sdstor/stgstrms.cxx +++ b/sot/source/sdstor/stgstrms.cxx @@ -1228,7 +1228,7 @@ void StgTmpStrm::SetSize(sal_uInt64 n) if( n > THRESHOLD ) { m_aName = utl::TempFile(nullptr, false).GetURL(); - SvFileStream* s = new SvFileStream( m_aName, StreamMode::READWRITE ); + std::unique_ptr<SvFileStream> s(new SvFileStream( m_aName, StreamMode::READWRITE )); const sal_uInt64 nCur = Tell(); sal_uInt64 i = nEndOfData; std::unique_ptr<sal_uInt8[]> p(new sal_uInt8[ 4096 ]); @@ -1270,10 +1270,9 @@ void StgTmpStrm::SetSize(sal_uInt64 n) if( i ) { SetError( s->GetError() ); - delete s; return; } - m_pStrm = s; + m_pStrm = s.release(); // Shrink the memory to 16 bytes, which seems to be the minimum ReAllocateMemory( - ( static_cast<long>(nEndOfData) - 16 ) ); } |