[Libreoffice-commits] core.git: package/source

Caolán McNamara caolanm at redhat.com
Mon Aug 17 06:55:38 PDT 2015


 package/source/zippackage/ZipPackage.cxx |   48 ++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 13 deletions(-)

New commits:
commit a19e2064c09275e9b053cc6c13d319c1a5c1c992
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Aug 17 14:54:01 2015 +0100

    avoid possible leak on exception
    
    Change-Id: Id3c16e5fedc5e57c8daccafa25bdb2fbbd0131b0

diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 8f1b3da..1304e0b 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 )
         {


More information about the Libreoffice-commits mailing list