ucb/source/ucp/webdav-curl/DAVSessionFactory.cxx |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

New commits:
commit e30f85f5b4de09a2e9fbe7f4c4af5ca7364e96ae
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Sep 12 16:13:21 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Sep 14 09:52:43 2022 +0200

    cid#1500603 Resource leak
    
    don't mix std::unique_ptr and rtl::Reference
    
    I don't know why mess around with osl_atomic_increment/osl_atomic_decrement,
    but at least sync with the pattern in use at
    ucb/source/ucp/tdoc/tdoc_storage.cxx StorageElementFactory::createStorage
    
    Change-Id: I25fc57d8e886bab3990a63543212efa67ac9772f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139811
    Tested-by: Jenkins
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/ucb/source/ucp/webdav-curl/DAVSessionFactory.cxx 
b/ucb/source/ucp/webdav-curl/DAVSessionFactory.cxx
index f2379d2cc33c..910e7f04b959 100644
--- a/ucb/source/ucp/webdav-curl/DAVSessionFactory.cxx
+++ b/ucb/source/ucp/webdav-curl/DAVSessionFactory.cxx
@@ -44,12 +44,12 @@ rtl::Reference< DAVSession > 
DAVSessionFactory::createDAVSession(
 
     if ( aIt == m_aMap.end() )
     {
-        std::unique_ptr< DAVSession > xElement(
+        rtl::Reference< CurlSession > xElement(
             new CurlSession(rxContext, this, inUri, rFlags, *m_xProxyDecider) 
);
 
         aIt = m_aMap.emplace(  inUri, xElement.get() ).first;
+
         aIt->second->m_aContainerIt = aIt;
-        xElement.release();
         return aIt->second;
     }
     else if ( osl_atomic_increment( &aIt->second->m_nRefCount ) > 1 )
@@ -63,9 +63,10 @@ rtl::Reference< DAVSession > 
DAVSessionFactory::createDAVSession(
         osl_atomic_decrement( &aIt->second->m_nRefCount );
         aIt->second->m_aContainerIt = m_aMap.end();
 
-        aIt->second = new CurlSession(rxContext, this, inUri, rFlags, 
*m_xProxyDecider);
+        rtl::Reference< CurlSession > xNewStorage = new CurlSession(rxContext, 
this, inUri, rFlags, *m_xProxyDecider);
+        aIt->second = xNewStorage.get();
         aIt->second->m_aContainerIt = aIt;
-        return aIt->second;
+        return xNewStorage;
     }
 }
 

Reply via email to