From e30f85f5b4de09a2e9fbe7f4c4af5ca7364e96ae Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 12 Sep 2022 16:13:21 +0100 Subject: cid#1500603 Resource leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Caolán McNamara --- ucb/source/ucp/webdav-curl/DAVSessionFactory.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ucb') 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; } } -- cgit