From 7764ae70b04058a64a3999529e98d1115ba59d1c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 7 Sep 2018 15:47:40 +0200 Subject: [PATCH] clang bugprone-unused-return-value most of these changes just make the change of ownership when using std::unique_ptr clearer, but there is one definite leak fix in PlainTextFilterDetect::detect Change-Id: I8282a68007222a4fee84004f394bde0cca8569e9 Reviewed-on: https://gerrit.libreoffice.org/60159 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- basctl/source/basicide/bastype2.cxx | 3 +-- binaryurp/source/reader.cxx | 6 ++---- codemaker/source/javamaker/javatype.cxx | 6 ++---- filter/source/textfilterdetect/filterdetect.cxx | 3 +-- package/source/zippackage/ZipPackageStream.cxx | 8 +++----- registry/source/regimpl.cxx | 3 +-- sd/source/ui/tools/SdGlobalResourceContainer.cxx | 5 +---- sw/source/core/crsr/swcrsr.cxx | 6 ++---- ucb/source/ucp/webdav-neon/DAVSessionFactory.cxx | 3 +-- 9 files changed, 14 insertions(+), 29 deletions(-) diff --git a/basctl/source/basicide/bastype2.cxx b/basctl/source/basicide/bastype2.cxx index 5997980df2ea..d8fe8efdc59a 100644 --- a/basctl/source/basicide/bastype2.cxx +++ b/basctl/source/basicide/bastype2.cxx @@ -701,9 +701,8 @@ SvTreeListEntry* TreeListBox::AddEntry( { SvTreeListEntry* p = InsertEntry( rText, rImage, rImage, pParent, bChildrenOnDemand, TREELIST_APPEND, - aUserData.get() + aUserData.release() ); - aUserData.release(); return p; } diff --git a/binaryurp/source/reader.cxx b/binaryurp/source/reader.cxx index fa5e91be704e..c40aeadea7df 100644 --- a/binaryurp/source/reader.cxx +++ b/binaryurp/source/reader.cxx @@ -335,9 +335,8 @@ void Reader::readMessage(Unmarshal & unmarshal) { bridge_->incrementActiveCalls(); } uno_threadpool_putJob( - bridge_->getThreadPool(), tid.getHandle(), req.get(), &request, + bridge_->getThreadPool(), tid.getHandle(), req.release(), &request, !synchronous); - req.release(); } } @@ -443,9 +442,8 @@ void Reader::readReplyMessage(Unmarshal & unmarshal, sal_uInt8 flags1) { std::unique_ptr< IncomingReply > resp( new IncomingReply(exc, ret, outArgs)); uno_threadpool_putJob( - bridge_->getThreadPool(), tid.getHandle(), resp.get(), nullptr, + bridge_->getThreadPool(), tid.getHandle(), resp.release(), nullptr, false); - resp.release(); break; } case OutgoingRequest::KIND_REQUEST_CHANGE: diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx index 5530392b278b..944f1a0aca9f 100644 --- a/codemaker/source/javamaker/javatype.cxx +++ b/codemaker/source/javamaker/javatype.cxx @@ -764,8 +764,7 @@ void handleEnumType( std::unique_ptr< ClassFile::Code > blockCode(cf->newCode()); blockCode->instrGetstatic(className, pair.second, classDescriptor); blockCode->instrAreturn(); - blocks.push_back(blockCode.get()); - blockCode.release(); + blocks.push_back(blockCode.release()); } code->instrTableswitch(defCode.get(), min, blocks); for (ClassFile::Code *p : blocks) @@ -783,8 +782,7 @@ void handleEnumType( std::unique_ptr< ClassFile::Code > blockCode(cf->newCode()); blockCode->instrGetstatic(className, pair.second, classDescriptor); blockCode->instrAreturn(); - blocks.emplace_back(pair.first, blockCode.get()); - blockCode.release(); + blocks.emplace_back(pair.first, blockCode.release()); } code->instrLookupswitch(defCode.get(), blocks); for (const std::pair< sal_Int32, ClassFile::Code * >& pair : blocks) diff --git a/filter/source/textfilterdetect/filterdetect.cxx b/filter/source/textfilterdetect/filterdetect.cxx index 3eeb0b1ee485..cb0055c34565 100644 --- a/filter/source/textfilterdetect/filterdetect.cxx +++ b/filter/source/textfilterdetect/filterdetect.cxx @@ -171,8 +171,7 @@ OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence pDecompressedStream(new SvMemoryStream()); if (aCodecGZ.AttemptDecompression(*pInStream, *pDecompressedStream)) { - uno::Reference xStreamDecompressed(new utl::OStreamWrapper(*pDecompressedStream)); - pDecompressedStream.release(); + uno::Reference xStreamDecompressed(new utl::OStreamWrapper(std::move(pDecompressedStream))); aMediaDesc[MediaDescriptor::PROP_STREAM()] <<= xStreamDecompressed; aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()] <<= xStreamDecompressed->getInputStream(); OUString aURL = aMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), OUString() ); diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index 5fe4d0ef80c5..5e62b8bf1aff 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -727,10 +727,9 @@ bool ZipPackageStream::saveChild( if ( m_bRawStream ) xStream->skipBytes( m_nMagicalHackPos ); - ZipOutputStream::setEntry(pTempEntry); - rZipOut.writeLOC(pTempEntry); // the entry is provided to the ZipOutputStream that will delete it - pAutoTempEntry.release(); + ZipOutputStream::setEntry(pAutoTempEntry.release()); + rZipOut.writeLOC(pTempEntry); uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize ); sal_Int32 nLength; @@ -797,9 +796,8 @@ bool ZipPackageStream::saveChild( try { - ZipOutputStream::setEntry(pTempEntry); // the entry is provided to the ZipOutputStream that will delete it - pAutoTempEntry.release(); + ZipOutputStream::setEntry(pAutoTempEntry.release()); if (pTempEntry->nMethod == STORED) { diff --git a/registry/source/regimpl.cxx b/registry/source/regimpl.cxx index a7647b9d512f..ac065a3e65a3 100644 --- a/registry/source/regimpl.cxx +++ b/registry/source/regimpl.cxx @@ -700,8 +700,7 @@ RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName, } std::unique_ptr< ORegKey > p(new ORegKey(path, this)); - i = m_openKeyTable.insert(std::make_pair(path, p.get())).first; - p.release(); + i = m_openKeyTable.insert(std::make_pair(path, p.release())).first; } else { i->second->acquire(); } diff --git a/sd/source/ui/tools/SdGlobalResourceContainer.cxx b/sd/source/ui/tools/SdGlobalResourceContainer.cxx index b6408cdf04be..26ec1df742db 100644 --- a/sd/source/ui/tools/SdGlobalResourceContainer.cxx +++ b/sd/source/ui/tools/SdGlobalResourceContainer.cxx @@ -99,7 +99,7 @@ void SdGlobalResourceContainer::AddResource ( mpImpl->maResources.end(), pResource.get()); if (iResource == mpImpl->maResources.end()) - mpImpl->maResources.push_back(pResource.get()); + mpImpl->maResources.push_back(pResource.release()); else { // Because the given resource is a unique_ptr it is highly unlikely @@ -107,9 +107,6 @@ void SdGlobalResourceContainer::AddResource ( SAL_WARN ( "sd.tools", "SdGlobalResourceContainer:AddResource(): Resource added twice."); } - // We can not put the unique_ptr into the vector so we release the - // unique_ptr and document that we take ownership explicitly. - pResource.release(); } void SdGlobalResourceContainer::AddResource ( diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx index 2b934cb6c576..1b74af2faa58 100644 --- a/sw/source/core/crsr/swcrsr.cxx +++ b/sw/source/core/crsr/swcrsr.cxx @@ -964,7 +964,7 @@ sal_uLong SwCursor::FindAll( SwFindParas& rParas, { // put cursor as copy of current into ring // chaining points always to first created, so forward - std::unique_ptr< SwCursor > pSav( Create( this ) ); // save the current cursor + SwCursor* pSav = Create( this ); // save the current cursor // if already outside of body text search from this position or start at // 1. base section @@ -995,7 +995,6 @@ sal_uLong SwCursor::FindAll( SwFindParas& rParas, DeleteMark(); return 0; } - pSav.release(); if( !( FindRanges::InSelAll & eFndRngs )) { @@ -1021,7 +1020,7 @@ sal_uLong SwCursor::FindAll( SwFindParas& rParas, } else if( FindRanges::InSelAll & eFndRngs ) { - std::unique_ptr< SwCursor> pSav( Create( this ) ); // save the current cursor + SwCursor* pSav = Create( this ); // save the current cursor const SwNode* pSttNd = ( FindRanges::InBodyOnly & eFndRngs ) ? rNds.GetEndOfContent().StartOfSectionNode() @@ -1048,7 +1047,6 @@ sal_uLong SwCursor::FindAll( SwFindParas& rParas, DeleteMark(); return 0; } - pSav.release(); while( GetNext() != this ) delete GetNext(); diff --git a/ucb/source/ucp/webdav-neon/DAVSessionFactory.cxx b/ucb/source/ucp/webdav-neon/DAVSessionFactory.cxx index 434c924d5932..b49a2cad68f1 100644 --- a/ucb/source/ucp/webdav-neon/DAVSessionFactory.cxx +++ b/ucb/source/ucp/webdav-neon/DAVSessionFactory.cxx @@ -70,9 +70,8 @@ rtl::Reference< DAVSession > DAVSessionFactory::createDAVSession( std::unique_ptr< DAVSession > xElement( new NeonSession( this, inUri, rFlags, *m_xProxyDecider.get() ) ); - aIt = m_aMap.emplace( inUri, xElement.get() ).first; + aIt = m_aMap.emplace( inUri, xElement.release() ).first; aIt->second->m_aContainerIt = aIt; - xElement.release(); return aIt->second; } else if ( osl_atomic_increment( &aIt->second->m_nRefCount ) > 1 )