diff options
author | Noel <noel.grandin@collabora.co.uk> | 2021-02-21 12:34:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-02-21 19:00:26 +0100 |
commit | e150c78cdfbe112bd880107b476ac42e72d4643c (patch) | |
tree | 8f67a46bd60ee89d28d485f0ada90ab7871566cc /package/source | |
parent | bb8fb3237c9d1b9516f5803d476c1db09570c2dc (diff) |
loplugin:refcounting in package..sax
Change-Id: I83618f54a4117cd81d8626307716129a761e14c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111274
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'package/source')
-rw-r--r-- | package/source/manifest/ManifestExport.cxx | 31 | ||||
-rw-r--r-- | package/source/xstor/owriteablestream.cxx | 30 | ||||
-rw-r--r-- | package/source/xstor/xstorage.cxx | 12 | ||||
-rw-r--r-- | package/source/xstor/xstorage.hxx | 2 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 16 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageStream.cxx | 7 |
6 files changed, 37 insertions, 61 deletions
diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx index 2f6f1ea0d913..c3c4be339646 100644 --- a/package/source/manifest/ManifestExport.cxx +++ b/package/source/manifest/ManifestExport.cxx @@ -32,6 +32,7 @@ #include <osl/diagnose.h> #include <rtl/ustrbuf.hxx> +#include <rtl/ref.hxx> #include <sal/log.hxx> #include <comphelper/base64.hxx> #include <comphelper/documentconstants.hxx> @@ -119,7 +120,7 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con const OUString sPBKDF2_Name ( PBKDF2_NAME ); const OUString sPGP_Name ( PGP_NAME ); - ::comphelper::AttributeList * pRootAttrList = new ::comphelper::AttributeList; + rtl::Reference<::comphelper::AttributeList> pRootAttrList = new ::comphelper::AttributeList; // find the mediatype of the document if any OUString aDocMediaType; @@ -211,8 +212,6 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con } } - uno::Reference < xml::sax::XAttributeList > xRootAttrList (pRootAttrList); - xHandler->startDocument(); uno::Reference < xml::sax::XExtendedDocumentHandler > xExtHandler ( xHandler, uno::UNO_QUERY ); if ( xExtHandler.is() && bProvideDTD ) @@ -220,7 +219,7 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con xExtHandler->unknown ( MANIFEST_DOCTYPE ); xHandler->ignorableWhitespace ( sWhiteSpace ); } - xHandler->startElement( sManifestElement, xRootAttrList ); + xHandler->startElement( sManifestElement, pRootAttrList ); const uno::Any *pKeyInfoProperty = nullptr; if ( pRootFolderPropSeq ) @@ -271,14 +270,13 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con xHandler->startElement(isODF13 ? sEncryptedKeyElement13 : sEncryptedKeyElement, nullptr); xHandler->ignorableWhitespace ( sWhiteSpace ); - ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; - uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList); + rtl::Reference<::comphelper::AttributeList> pNewAttrList = new ::comphelper::AttributeList; // TODO: the algorithm should rather be configurable pNewAttrList->AddAttribute( isODF13 ? sAlgorithmAttribute13 : sAlgorithmAttribute, sCdataAttribute, "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" ); - xHandler->startElement(isODF13 ? sEncryptionMethodElement13 : sEncryptionMethodElement, xNewAttrList); + xHandler->startElement(isODF13 ? sEncryptionMethodElement13 : sEncryptionMethodElement, pNewAttrList); xHandler->endElement(isODF13 ? sEncryptionMethodElement13 : sEncryptionMethodElement); xHandler->ignorableWhitespace ( sWhiteSpace ); @@ -339,7 +337,7 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con // now write individual file entries for (const uno::Sequence<beans::PropertyValue>& rSequence : rManList) { - ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList; + rtl::Reference<::comphelper::AttributeList> pAttrList = new ::comphelper::AttributeList; OUString aString; const uno::Any *pVector = nullptr, *pSalt = nullptr, *pIterationCount = nullptr, *pDigest = nullptr, *pDigestAlg = nullptr, *pEncryptAlg = nullptr, *pStartKeyAlg = nullptr, *pDerivedKeySize = nullptr; for (const beans::PropertyValue& rValue : rSequence) @@ -386,13 +384,11 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con } xHandler->ignorableWhitespace ( sWhiteSpace ); - uno::Reference < xml::sax::XAttributeList > xAttrList ( pAttrList ); - xHandler->startElement( sFileEntryElement , xAttrList); + xHandler->startElement( sFileEntryElement , pAttrList); if ( pVector && pSalt && pIterationCount && pDigest && pDigestAlg && pEncryptAlg && pStartKeyAlg && pDerivedKeySize ) { // ==== Encryption Data - ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; - uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList); + rtl::Reference<::comphelper::AttributeList> pNewAttrList = new ::comphelper::AttributeList; OUStringBuffer aBuffer; uno::Sequence < sal_Int8 > aSequence; @@ -414,11 +410,10 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con ::comphelper::Base64::encode(aBuffer, aSequence); pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - xHandler->startElement( sEncryptionDataElement , xNewAttrList); + xHandler->startElement( sEncryptionDataElement , pNewAttrList); // ==== Algorithm pNewAttrList = new ::comphelper::AttributeList; - xNewAttrList = pNewAttrList; sal_Int32 nEncAlgID = 0; sal_Int32 nDerivedKeySize = 0; @@ -448,7 +443,7 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con pNewAttrList->AddAttribute ( sInitialisationVectorAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->startElement( sAlgorithmElement , xNewAttrList); + xHandler->startElement( sAlgorithmElement , pNewAttrList); xHandler->ignorableWhitespace ( sWhiteSpace ); xHandler->endElement( sAlgorithmElement ); @@ -456,7 +451,6 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con { // ==== Start Key Generation pNewAttrList = new ::comphelper::AttributeList; - xNewAttrList = pNewAttrList; OUString sStartKeyAlg; OUString sStartKeySize; @@ -481,14 +475,13 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sStartKeySize ); xHandler->ignorableWhitespace ( sWhiteSpace ); - xHandler->startElement( sStartKeyGenerationElement , xNewAttrList); + xHandler->startElement( sStartKeyGenerationElement , pNewAttrList); xHandler->ignorableWhitespace ( sWhiteSpace ); xHandler->endElement( sStartKeyGenerationElement ); } // ==== Key Derivation pNewAttrList = new ::comphelper::AttributeList; - xNewAttrList = pNewAttrList; if (pKeyInfoProperty) { @@ -522,7 +515,7 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con } xHandler->ignorableWhitespace(sWhiteSpace); - xHandler->startElement(sKeyDerivationElement, xNewAttrList); + xHandler->startElement(sKeyDerivationElement, pNewAttrList); xHandler->ignorableWhitespace(sWhiteSpace); xHandler->endElement(sKeyDerivationElement); diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 77a34c533653..1b914138a0c1 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -1234,14 +1234,9 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre if ( !xInStream.is() ) throw io::IOException(); - OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); - uno::Reference< io::XStream > xCompStream( - static_cast< ::cppu::OWeakObject* >( pStream ), - uno::UNO_QUERY ); - SAL_WARN_IF( !xCompStream.is(), "package.xstor", "OInputCompStream MUST provide XStream interfaces!" ); - - m_aInputStreamsVector.push_back( pStream ); - return xCompStream; + rtl::Reference<OInputCompStream> pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); + m_aInputStreamsVector.push_back( pStream.get() ); + return pStream; } else if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::SEEKABLEREAD ) { @@ -1256,14 +1251,9 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre if ( !xInStream.is() ) throw io::IOException(); - OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); - uno::Reference< io::XStream > xSeekStream( - static_cast< ::cppu::OWeakObject* >( pStream ), - uno::UNO_QUERY ); - SAL_WARN_IF( !xSeekStream.is(), "package.xstor", "OInputSeekStream MUST provide XStream interfaces!" ); - - m_aInputStreamsVector.push_back( pStream ); - return xSeekStream; + rtl::Reference<OInputSeekStream> pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); + m_aInputStreamsVector.push_back( pStream.get() ); + return pStream; } else if ( ( nStreamMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE ) { @@ -1308,12 +1298,14 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre // xStream = GetTempFileAsStream(); } + rtl::Reference<OWriteStream> tmp; if ( !xStream.is() ) - m_pAntiImpl = new OWriteStream( this, bHierarchyAccess ); + tmp = new OWriteStream( this, bHierarchyAccess ); else - m_pAntiImpl = new OWriteStream( this, xStream, bHierarchyAccess ); + tmp = new OWriteStream( this, xStream, bHierarchyAccess ); - return m_pAntiImpl; + m_pAntiImpl = tmp.get(); + return tmp; } throw lang::IllegalArgumentException(); // TODO diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index 13e93c9da9ad..6b2a5b02c5d1 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -190,7 +190,6 @@ OStorage_Impl::OStorage_Impl( uno::Reference< io::XInputStream > const & xInpu , m_bControlMediaType( false ) , m_bMTFallbackUsed( false ) , m_bControlVersion( false ) -, m_pSwitchStream( nullptr ) , m_nStorageType( nStorageType ) , m_pRelStorElement( nullptr ) , m_nRelInfoStatus( RELINFO_NO_INIT ) @@ -231,7 +230,6 @@ OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > const & xStream, , m_bControlMediaType( false ) , m_bMTFallbackUsed( false ) , m_bControlVersion( false ) -, m_pSwitchStream( nullptr ) , m_nStorageType( nStorageType ) , m_pRelStorElement( nullptr ) , m_nRelInfoStatus( RELINFO_NO_INIT ) @@ -243,7 +241,7 @@ OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > const & xStream, if ( m_nStorageMode & embed::ElementModes::WRITE ) { m_pSwitchStream = new SwitchablePersistenceStream(xContext, xStream); - m_xStream = static_cast< io::XStream* >( m_pSwitchStream ); + m_xStream = static_cast< io::XStream* >( m_pSwitchStream.get() ); } else { @@ -275,7 +273,6 @@ OStorage_Impl::OStorage_Impl( OStorage_Impl* pParent, , m_bControlMediaType( false ) , m_bMTFallbackUsed( false ) , m_bControlVersion( false ) -, m_pSwitchStream( nullptr ) , m_nStorageType( nStorageType ) , m_pRelStorElement( nullptr ) , m_nRelInfoStatus( RELINFO_NO_INIT ) @@ -1617,8 +1614,7 @@ void OStorage_Impl::CreateRelStorage() if (!m_pRelStorElement->m_xStorage) throw uno::RuntimeException( THROW_WHERE ); - OStorage* pResultStorage = new OStorage(m_pRelStorElement->m_xStorage.get(), false); - m_xRelStorage.set( static_cast<embed::XStorage*>(pResultStorage) ); + m_xRelStorage = new OStorage(m_pRelStorElement->m_xStorage.get(), false); } void OStorage_Impl::CommitStreamRelInfo( std::u16string_view rName, SotElement_Impl const * pStreamElement ) @@ -2408,8 +2404,8 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement( throw io::IOException( THROW_WHERE ); // TODO: general_error bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ); - OStorage* pResultStorage = new OStorage(pElement->m_xStorage.get(), bReadOnlyWrap); - xResult.set( static_cast<embed::XStorage*>(pResultStorage) ); + rtl::Reference<OStorage> pResultStorage = new OStorage(pElement->m_xStorage.get(), bReadOnlyWrap); + xResult = pResultStorage; if ( bReadOnlyWrap ) { diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx index cddaa7d6fbe1..14d11a8de0b2 100644 --- a/package/source/xstor/xstorage.hxx +++ b/package/source/xstor/xstorage.hxx @@ -155,7 +155,7 @@ struct OStorage_Impl bool m_bControlVersion; OUString m_aVersion; - SwitchablePersistenceStream* m_pSwitchStream; + rtl::Reference<SwitchablePersistenceStream> m_pSwitchStream; sal_Int32 m_nStorageType; // the mode in which the storage is used diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index c91947992047..3de64f6502b2 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -558,10 +558,10 @@ void ZipPackage::getZipFileContents() break; if ( !pCurrent->hasByName( sTemp ) ) { - ZipPackageFolder* pPkgFolder = new ZipPackageFolder(m_xContext, m_nFormat, m_bAllowRemoveOnInsert); + rtl::Reference<ZipPackageFolder> pPkgFolder = new ZipPackageFolder(m_xContext, m_nFormat, m_bAllowRemoveOnInsert); pPkgFolder->setName( sTemp ); pPkgFolder->doSetParent( pCurrent ); - pCurrent = pPkgFolder; + pCurrent = pPkgFolder.get(); } else { @@ -582,7 +582,7 @@ void ZipPackage::getZipFileContents() if (!pCurrent->hasByName(sTemp)) { - ZipPackageStream *pPkgStream = new ZipPackageStream(*this, m_xContext, m_nFormat, m_bAllowRemoveOnInsert); + rtl::Reference<ZipPackageStream> pPkgStream = new ZipPackageStream(*this, m_xContext, m_nFormat, m_bAllowRemoveOnInsert); pPkgStream->SetPackageMember(true); pPkgStream->setZipEntryOnLoading(rEntry); pPkgStream->setName(sTemp); @@ -1056,8 +1056,7 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq // Write the manifest uno::Reference < XManifestWriter > xWriter = ManifestWriter::create( m_xContext ); ZipEntry * pEntry = new ZipEntry; - ZipPackageBuffer *pBuffer = new ZipPackageBuffer; - uno::Reference < XOutputStream > xManOutStream( *pBuffer, UNO_QUERY ); + rtl::Reference<ZipPackageBuffer> pBuffer = new ZipPackageBuffer; pEntry->sPath = "META-INF/manifest.xml"; pEntry->nMethod = DEFLATED; @@ -1065,7 +1064,7 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - xWriter->writeManifestSequence ( xManOutStream, comphelper::containerToSequence(aManList) ); + xWriter->writeManifestSequence ( pBuffer, comphelper::containerToSequence(aManList) ); sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); pBuffer->realloc( nBufferLength ); @@ -1082,8 +1081,7 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) { ZipEntry* pEntry = new ZipEntry; - ZipPackageBuffer *pBuffer = new ZipPackageBuffer; - uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY ); + rtl::Reference<ZipPackageBuffer> pBuffer = new ZipPackageBuffer; pEntry->sPath = "[Content_Types].xml"; pEntry->nMethod = DEFLATED; @@ -1125,7 +1123,7 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno: aOverridesSequence.realloc(nOverSeqLength); ::comphelper::OFOPXMLHelper::WriteContentSequence( - xConTypeOutStream, aDefaultsSequence, aOverridesSequence, m_xContext ); + pBuffer, aDefaultsSequence, aOverridesSequence, m_xContext ); sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); pBuffer->realloc( nBufferLength ); diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index 962d206ed1cb..fb1794841809 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -285,17 +285,14 @@ uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( uno::UNO_QUERY_THROW ); // create a package based on it - ZipPackage* pPackage = new ZipPackage( m_xContext ); - uno::Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) ); - if ( !xPackageAsFactory.is() ) - throw RuntimeException(THROW_WHERE ); + rtl::Reference<ZipPackage> pPackage = new ZipPackage( m_xContext ); Sequence< Any > aArgs( 1 ); aArgs[0] <<= xTempStream; pPackage->initialize( aArgs ); // create a new package stream - uno::Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY_THROW ); + uno::Reference< XDataSinkEncrSupport > xNewPackStream( pPackage->createInstance(), UNO_QUERY_THROW ); xNewPackStream->setDataStream( new WrapStreamForShare(GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef())); |