[Libreoffice-commits] core.git: ucb/Library_cached1.mk ucb/Library_srtrs1.mk ucb/Library_ucpftp1.mk ucb/source

Takeshi Abe tabe at fixedpoint.jp
Thu Jul 24 18:10:00 PDT 2014


 ucb/Library_cached1.mk                             |    2 ++
 ucb/Library_srtrs1.mk                              |    2 ++
 ucb/Library_ucpftp1.mk                             |    2 ++
 ucb/source/cacher/cachedcontentresultset.cxx       |    4 ++--
 ucb/source/sorter/sortresult.cxx                   |    5 ++---
 ucb/source/ucp/cmis/cmis_repo_content.cxx          |    8 ++++----
 ucb/source/ucp/file/filstr.cxx                     |   11 +++++------
 ucb/source/ucp/ftp/ftpurl.cxx                      |   19 ++++++++++---------
 ucb/source/ucp/webdav-neon/NeonPropFindRequest.cxx |    7 +++----
 9 files changed, 32 insertions(+), 28 deletions(-)

New commits:
commit a8b395bff2111d7bf086b4cb44081dce10cca364
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu Jul 24 23:09:24 2014 +0900

    Avoid possible memory leaks in case of exceptions
    
    Change-Id: I9983e858c4e634b4cac8ad42fa9b06b7ccc167d6

diff --git a/ucb/Library_cached1.mk b/ucb/Library_cached1.mk
index dee50bf..51f2395 100644
--- a/ucb/Library_cached1.mk
+++ b/ucb/Library_cached1.mk
@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,cached1))
 
 $(eval $(call gb_Library_set_componentfile,cached1,ucb/source/cacher/cached1))
 
+$(eval $(call gb_Library_use_external,cached1,boost_headers))
+
 $(eval $(call gb_Library_use_sdk_api,cached1))
 
 $(eval $(call gb_Library_use_libraries,cached1,\
diff --git a/ucb/Library_srtrs1.mk b/ucb/Library_srtrs1.mk
index e534de1..9cccba3 100644
--- a/ucb/Library_srtrs1.mk
+++ b/ucb/Library_srtrs1.mk
@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,srtrs1))
 
 $(eval $(call gb_Library_set_componentfile,srtrs1,ucb/source/sorter/srtrs1))
 
+$(eval $(call gb_Library_use_external,srtrs1,boost_headers))
+
 $(eval $(call gb_Library_use_sdk_api,srtrs1))
 
 $(eval $(call gb_Library_use_libraries,srtrs1,\
diff --git a/ucb/Library_ucpftp1.mk b/ucb/Library_ucpftp1.mk
index 68551d3..9c05490 100644
--- a/ucb/Library_ucpftp1.mk
+++ b/ucb/Library_ucpftp1.mk
@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,ucpftp1))
 
 $(eval $(call gb_Library_set_componentfile,ucpftp1,ucb/source/ucp/ftp/ucpftp1))
 
+$(eval $(call gb_Library_use_external,ucpftp1,boost_headers))
+
 $(eval $(call gb_Library_use_sdk_api,ucpftp1))
 
 $(eval $(call gb_Library_use_libraries,ucpftp1,\
diff --git a/ucb/source/cacher/cachedcontentresultset.cxx b/ucb/source/cacher/cachedcontentresultset.cxx
index 7cf7006..954aa09 100644
--- a/ucb/source/cacher/cachedcontentresultset.cxx
+++ b/ucb/source/cacher/cachedcontentresultset.cxx
@@ -28,6 +28,7 @@
 #include <rtl/ustring.hxx>
 #include <osl/diagnose.h>
 #include <comphelper/processfactory.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using namespace com::sun::star::beans;
 using namespace com::sun::star::lang;
@@ -475,7 +476,7 @@ CCRS_PropertySetInfo::CCRS_PropertySetInfo(
     if( nFetchDirection != -1 )
         nDeleted++;
 
-    Sequence< Property >* pOrigProps = new Sequence<Property> ( *m_pProperties );
+    boost::scoped_ptr<Sequence< Property > > pOrigProps(new Sequence<Property> ( *m_pProperties ));
     sal_Int32 nOrigProps = pOrigProps->getLength();
 
     m_pProperties->realloc( nOrigProps + 2 - nDeleted );//note that nDeleted is <= 2
@@ -513,7 +514,6 @@ CCRS_PropertySetInfo::CCRS_PropertySetInfo(
 
         m_nFetchDirectionPropertyHandle = rMyProp.Handle;
     }
-    delete pOrigProps;
 }
 
 CCRS_PropertySetInfo::~CCRS_PropertySetInfo()
diff --git a/ucb/source/sorter/sortresult.cxx b/ucb/source/sorter/sortresult.cxx
index 703b0aa..7a8b7c2 100644
--- a/ucb/source/sorter/sortresult.cxx
+++ b/ucb/source/sorter/sortresult.cxx
@@ -30,6 +30,7 @@
 #include <cppuhelper/interfacecontainer.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <osl/diagnose.h>
+#include <boost/scoped_array.hpp>
 
 using namespace com::sun::star::beans;
 using namespace com::sun::star::container;
@@ -1588,7 +1589,7 @@ void SortedResultSet::Move( sal_IntPtr nPos, sal_IntPtr nCount, sal_IntPtr nOffs
     }
 
     // remember the to be moved entries
-    sal_IntPtr *pTmpArr = new sal_IntPtr[ nCount ];
+    boost::scoped_array<sal_IntPtr> pTmpArr(new sal_IntPtr[ nCount ]);
     for ( i=0; i<nCount; i++ )
         pTmpArr[i] = (sal_IntPtr)maO2S.GetObject( (sal_uInt32)( nPos+i ) );
 
@@ -1624,8 +1625,6 @@ void SortedResultSet::Move( sal_IntPtr nPos, sal_IntPtr nCount, sal_IntPtr nOffs
     {
         maO2S.Replace( (void*)pTmpArr[ i ], (sal_uInt32)( nTo+i ) );
     }
-
-    delete [] pTmpArr;
 }
 
 
diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx
index 4d25049..ea99c35 100644
--- a/ucb/source/ucp/cmis/cmis_repo_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx
@@ -37,6 +37,7 @@
 #include "cmis_provider.hxx"
 #include "cmis_repo_content.hxx"
 #include "cmis_resultset.hxx"
+#include <boost/scoped_ptr.hpp>
 
 #define OUSTR_TO_STDSTR(s) string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
 #define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
@@ -177,17 +178,16 @@ namespace cmis
                             ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
                             ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) );
 
-                    libcmis::Session* session = libcmis::SessionFactory::createSession(
+                    boost::scoped_ptr<libcmis::Session> session(libcmis::SessionFactory::createSession(
                             OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ),
-                            rUsername, rPassword, "", false, oauth2Data );
-                    if (session == NULL )
+                            rUsername, rPassword, "", false, oauth2Data ));
+                    if (!session)
                         ucbhelper::cancelCommandExecution(
                                             ucb::IOErrorCode_INVALID_DEVICE,
                                             uno::Sequence< uno::Any >( 0 ),
                                             xEnv,
                                             OUString( ) );
                     m_aRepositories = session->getRepositories( );
-                    delete session;
                 }
                 catch (const libcmis::Exception& e)
                 {
diff --git a/ucb/source/ucp/file/filstr.cxx b/ucb/source/ucp/file/filstr.cxx
index bd8ee9b..95391728 100644
--- a/ucb/source/ucp/file/filstr.cxx
+++ b/ucb/source/ucp/file/filstr.cxx
@@ -23,6 +23,7 @@
 #include "filstr.hxx"
 #include "shell.hxx"
 #include "prov.hxx"
+#include <boost/scoped_array.hpp>
 
 using namespace fileaccess;
 using namespace com::sun::star;
@@ -142,10 +143,10 @@ XStream_impl::readBytes(
     if( ! m_nIsOpen )
         throw io::IOException( THROW_WHERE );
 
-    sal_Int8 * buffer;
+    boost::scoped_array<sal_Int8> buffer;
     try
     {
-        buffer = new sal_Int8[nBytesToRead];
+        buffer.reset(new sal_Int8[nBytesToRead]);
     }
     catch (const std::bad_alloc&)
     {
@@ -154,14 +155,12 @@ XStream_impl::readBytes(
     }
 
     sal_uInt64 nrc(0);
-    if(m_aFile.read( (void* )buffer,sal_uInt64(nBytesToRead),nrc )
+    if(m_aFile.read( buffer.get(),sal_uInt64(nBytesToRead),nrc )
        != osl::FileBase::E_None)
     {
-        delete[] buffer;
         throw io::IOException( THROW_WHERE );
     }
-    aData = uno::Sequence< sal_Int8 > ( buffer, (sal_uInt32)nrc );
-    delete[] buffer;
+    aData = uno::Sequence< sal_Int8 > ( buffer.get(), (sal_uInt32)nrc );
     return ( sal_Int32 ) nrc;
 }
 
diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx
index 6b176a5..1fb36be 100644
--- a/ucb/source/ucp/ftp/ftpurl.cxx
+++ b/ucb/source/ucp/ftp/ftpurl.cxx
@@ -38,6 +38,7 @@
 #include "ftphandleprovider.hxx"
 #include "ftpcfunc.hxx"
 #include "ftpcontainer.hxx"
+#include <boost/scoped_array.hpp>
 
 using namespace ftp;
 using namespace com::sun::star::ucb;
@@ -159,17 +160,17 @@ void FTPURL::parse(const OUString& url)
        strncmp("ftp://",lower.getStr(),6))
         throw malformed_exception();
 
-    char *buffer = new char[1+aIdent.getLength()];
+    boost::scoped_array<char> buffer(new char[1+aIdent.getLength()]);
     const char* p2 = aIdent.getStr();
     p2 += 6;
 
     char ch;
-    char *p1 = buffer;      // determine "username:password at host:port"
+    char *p1 = buffer.get();      // determine "username:password at host:port"
     while((ch = *p2++) != '/' && ch)
         *p1++ = ch;
     *p1 = 0;
 
-    OUString aExpr(buffer, strlen(buffer), RTL_TEXTENCODING_UTF8);
+    OUString aExpr(buffer.get(), strlen(buffer.get()), RTL_TEXTENCODING_UTF8);
 
     sal_Int32 l = aExpr.indexOf('@');
     m_aHost = aExpr.copy(1+l);
@@ -203,26 +204,26 @@ void FTPURL::parse(const OUString& url)
     }
 
     while(ch) {  // now determine the pathsegments ...
-        p1 = buffer;
+        p1 = buffer.get();
         while((ch = *p2++) != '/' && ch)
             *p1++ = ch;
         *p1 = 0;
 
         if(buffer[0]) {
-            if( strcmp(buffer,"..") == 0 && !m_aPathSegmentVec.empty() && m_aPathSegmentVec.back() != ".." )
+            if( strcmp(buffer.get(),"..") == 0 && !m_aPathSegmentVec.empty() && m_aPathSegmentVec.back() != ".." )
                 m_aPathSegmentVec.pop_back();
-            else if(strcmp(buffer,".") == 0)
+            else if(strcmp(buffer.get(),".") == 0)
                 ; // Ignore
             else
                 // This is a legal name.
                 m_aPathSegmentVec.push_back(
-                    OUString(buffer,
-                                  strlen(buffer),
+                    OUString(buffer.get(),
+                                  strlen(buffer.get()),
                                   RTL_TEXTENCODING_UTF8));
         }
     }
 
-    delete[] buffer;
+    buffer.reset();
 
     if(m_bShowPassword)
         m_pFCP->setHost(m_aHost,
diff --git a/ucb/source/ucp/webdav-neon/NeonPropFindRequest.cxx b/ucb/source/ucp/webdav-neon/NeonPropFindRequest.cxx
index c5945f2..73b6c7c 100644
--- a/ucb/source/ucp/webdav-neon/NeonPropFindRequest.cxx
+++ b/ucb/source/ucp/webdav-neon/NeonPropFindRequest.cxx
@@ -37,6 +37,7 @@
 #include "LockSequence.hxx"
 #include "LockEntrySequence.hxx"
 #include "UCBDeadPropertyValue.hxx"
+#include <boost/scoped_array.hpp>
 
 using namespace com::sun::star::uno;
 using namespace com::sun::star::ucb;
@@ -248,7 +249,7 @@ NeonPropFindRequest::NeonPropFindRequest( HttpSession* inSession,
     int thePropCount = inPropNames.size();
     if ( thePropCount > 0 )
     {
-        NeonPropName* thePropNames = new NeonPropName[ thePropCount + 1 ];
+        boost::scoped_array<NeonPropName> thePropNames(new NeonPropName[ thePropCount + 1 ]);
         int theIndex;
 
         for ( theIndex = 0; theIndex < thePropCount; theIndex ++ )
@@ -265,15 +266,13 @@ NeonPropFindRequest::NeonPropFindRequest( HttpSession* inSession,
             nError = ne_simple_propfind( inSession,
                                          inPath,
                                          inDepth,
-                                         thePropNames,
+                                         thePropNames.get(),
                                          NPFR_propfind_results,
                                          &ioResources );
         }
 
         for ( theIndex = 0; theIndex < thePropCount; theIndex ++ )
             free( (void *)thePropNames[ theIndex ].name );
-
-        delete [] thePropNames;
     }
     else
     {


More information about the Libreoffice-commits mailing list