summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-08-17 14:54:01 +0100
committerCaolán McNamara <caolanm@redhat.com>2015-08-17 14:55:14 +0100
commita19e2064c09275e9b053cc6c13d319c1a5c1c992 (patch)
tree82e8e6b753f8597f53d3945cf6c0a22fa1c40950 /package
parent6efbd4bb63e293080d0566664b1e33f6ffdf36e5 (diff)
avoid possible leak on exception
Change-Id: Id3c16e5fedc5e57c8daccafa25bdb2fbbd0131b0
Diffstat (limited to 'package')
-rw-r--r--package/source/zippackage/ZipPackage.cxx48
1 files changed, 35 insertions, 13 deletions
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 )
{