From a19e2064c09275e9b053cc6c13d319c1a5c1c992 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 17 Aug 2015 14:54:01 +0100 Subject: avoid possible leak on exception Change-Id: Id3c16e5fedc5e57c8daccafa25bdb2fbbd0131b0 --- package/source/zippackage/ZipPackage.cxx | 48 +++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'package') diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 8f1b3dab5f76..1304e0ba4f3a 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -1117,6 +1117,33 @@ void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream m_pZipFile = new ZipFile ( m_xContentStream, m_xContext, false ); } +namespace +{ + class RandomPool + { + private: + rtlRandomPool m_aRandomPool; + public: + RandomPool() + { + // Get a random number generator and seed it with current timestamp + TimeValue aTime; + osl_getSystemTime( &aTime ); + m_aRandomPool = rtl_random_createPool (); + rtl_random_addBytes (m_aRandomPool, &aTime, 8); + } + rtlRandomPool get() + { + return m_aRandomPool; + } + ~RandomPool() + { + // Clean up random pool memory + rtl_random_destroyPool(m_aRandomPool); + } + }; +} + uno::Reference< io::XInputStream > ZipPackage::writeTempFile() { // In case the target local file does not exist or empty @@ -1218,20 +1245,15 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() aManList.push_back( aPropSeq ); } - // Get a random number generator and seed it with current timestamp - // This will be used to generate random salt and initialisation vectors - // for encrypted streams - TimeValue aTime; - osl_getSystemTime( &aTime ); - rtlRandomPool aRandomPool = rtl_random_createPool (); - rtl_random_addBytes ( aRandomPool, &aTime, 8 ); - - // call saveContents ( it will recursively save sub-directories - OUString aEmptyString; - m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, GetEncryptionKey(), aRandomPool ); + { + // This will be used to generate random salt and initialisation vectors + // for encrypted streams + RandomPool aRandomPool; - // Clean up random pool memory - rtl_random_destroyPool ( aRandomPool ); + // call saveContents ( it will recursively save sub-directories + OUString aEmptyString; + m_pRootFolder->saveContents(aEmptyString, aManList, aZipOut, GetEncryptionKey(), aRandomPool.get()); + } if( m_nFormat == embed::StorageFormats::PACKAGE ) { -- cgit