Kaydet (Commit) a8b395bf authored tarafından Takeshi Abe's avatar Takeshi Abe

Avoid possible memory leaks in case of exceptions

Change-Id: I9983e858c4e634b4cac8ad42fa9b06b7ccc167d6
üst 4f2f53e2
...@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,cached1)) ...@@ -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_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_sdk_api,cached1))
$(eval $(call gb_Library_use_libraries,cached1,\ $(eval $(call gb_Library_use_libraries,cached1,\
......
...@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,srtrs1)) ...@@ -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_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_sdk_api,srtrs1))
$(eval $(call gb_Library_use_libraries,srtrs1,\ $(eval $(call gb_Library_use_libraries,srtrs1,\
......
...@@ -12,6 +12,8 @@ $(eval $(call gb_Library_Library,ucpftp1)) ...@@ -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_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_sdk_api,ucpftp1))
$(eval $(call gb_Library_use_libraries,ucpftp1,\ $(eval $(call gb_Library_use_libraries,ucpftp1,\
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star::beans; using namespace com::sun::star::beans;
using namespace com::sun::star::lang; using namespace com::sun::star::lang;
...@@ -475,7 +476,7 @@ CCRS_PropertySetInfo::CCRS_PropertySetInfo( ...@@ -475,7 +476,7 @@ CCRS_PropertySetInfo::CCRS_PropertySetInfo(
if( nFetchDirection != -1 ) if( nFetchDirection != -1 )
nDeleted++; 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(); sal_Int32 nOrigProps = pOrigProps->getLength();
m_pProperties->realloc( nOrigProps + 2 - nDeleted );//note that nDeleted is <= 2 m_pProperties->realloc( nOrigProps + 2 - nDeleted );//note that nDeleted is <= 2
...@@ -513,7 +514,6 @@ CCRS_PropertySetInfo::CCRS_PropertySetInfo( ...@@ -513,7 +514,6 @@ CCRS_PropertySetInfo::CCRS_PropertySetInfo(
m_nFetchDirectionPropertyHandle = rMyProp.Handle; m_nFetchDirectionPropertyHandle = rMyProp.Handle;
} }
delete pOrigProps;
} }
CCRS_PropertySetInfo::~CCRS_PropertySetInfo() CCRS_PropertySetInfo::~CCRS_PropertySetInfo()
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/interfacecontainer.hxx>
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <boost/scoped_array.hpp>
using namespace com::sun::star::beans; using namespace com::sun::star::beans;
using namespace com::sun::star::container; using namespace com::sun::star::container;
...@@ -1588,7 +1589,7 @@ void SortedResultSet::Move( sal_IntPtr nPos, sal_IntPtr nCount, sal_IntPtr nOffs ...@@ -1588,7 +1589,7 @@ void SortedResultSet::Move( sal_IntPtr nPos, sal_IntPtr nCount, sal_IntPtr nOffs
} }
// remember the to be moved entries // 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++ ) for ( i=0; i<nCount; i++ )
pTmpArr[i] = (sal_IntPtr)maO2S.GetObject( (sal_uInt32)( nPos+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 ...@@ -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 ) ); maO2S.Replace( (void*)pTmpArr[ i ], (sal_uInt32)( nTo+i ) );
} }
delete [] pTmpArr;
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "cmis_provider.hxx" #include "cmis_provider.hxx"
#include "cmis_repo_content.hxx" #include "cmis_repo_content.hxx"
#include "cmis_resultset.hxx" #include "cmis_resultset.hxx"
#include <boost/scoped_ptr.hpp>
#define OUSTR_TO_STDSTR(s) string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() ) #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 ) #define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
...@@ -177,17 +178,16 @@ namespace cmis ...@@ -177,17 +178,16 @@ namespace cmis
ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI, ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) ); 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( ) ), OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ),
rUsername, rPassword, "", false, oauth2Data ); rUsername, rPassword, "", false, oauth2Data ));
if (session == NULL ) if (!session)
ucbhelper::cancelCommandExecution( ucbhelper::cancelCommandExecution(
ucb::IOErrorCode_INVALID_DEVICE, ucb::IOErrorCode_INVALID_DEVICE,
uno::Sequence< uno::Any >( 0 ), uno::Sequence< uno::Any >( 0 ),
xEnv, xEnv,
OUString( ) ); OUString( ) );
m_aRepositories = session->getRepositories( ); m_aRepositories = session->getRepositories( );
delete session;
} }
catch (const libcmis::Exception& e) catch (const libcmis::Exception& e)
{ {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "filstr.hxx" #include "filstr.hxx"
#include "shell.hxx" #include "shell.hxx"
#include "prov.hxx" #include "prov.hxx"
#include <boost/scoped_array.hpp>
using namespace fileaccess; using namespace fileaccess;
using namespace com::sun::star; using namespace com::sun::star;
...@@ -142,10 +143,10 @@ XStream_impl::readBytes( ...@@ -142,10 +143,10 @@ XStream_impl::readBytes(
if( ! m_nIsOpen ) if( ! m_nIsOpen )
throw io::IOException( THROW_WHERE ); throw io::IOException( THROW_WHERE );
sal_Int8 * buffer; boost::scoped_array<sal_Int8> buffer;
try try
{ {
buffer = new sal_Int8[nBytesToRead]; buffer.reset(new sal_Int8[nBytesToRead]);
} }
catch (const std::bad_alloc&) catch (const std::bad_alloc&)
{ {
...@@ -154,14 +155,12 @@ XStream_impl::readBytes( ...@@ -154,14 +155,12 @@ XStream_impl::readBytes(
} }
sal_uInt64 nrc(0); 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) != osl::FileBase::E_None)
{ {
delete[] buffer;
throw io::IOException( THROW_WHERE ); throw io::IOException( THROW_WHERE );
} }
aData = uno::Sequence< sal_Int8 > ( buffer, (sal_uInt32)nrc ); aData = uno::Sequence< sal_Int8 > ( buffer.get(), (sal_uInt32)nrc );
delete[] buffer;
return ( sal_Int32 ) nrc; return ( sal_Int32 ) nrc;
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "ftphandleprovider.hxx" #include "ftphandleprovider.hxx"
#include "ftpcfunc.hxx" #include "ftpcfunc.hxx"
#include "ftpcontainer.hxx" #include "ftpcontainer.hxx"
#include <boost/scoped_array.hpp>
using namespace ftp; using namespace ftp;
using namespace com::sun::star::ucb; using namespace com::sun::star::ucb;
...@@ -159,17 +160,17 @@ void FTPURL::parse(const OUString& url) ...@@ -159,17 +160,17 @@ void FTPURL::parse(const OUString& url)
strncmp("ftp://",lower.getStr(),6)) strncmp("ftp://",lower.getStr(),6))
throw malformed_exception(); 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(); const char* p2 = aIdent.getStr();
p2 += 6; p2 += 6;
char ch; char ch;
char *p1 = buffer; // determine "username:password@host:port" char *p1 = buffer.get(); // determine "username:password@host:port"
while((ch = *p2++) != '/' && ch) while((ch = *p2++) != '/' && ch)
*p1++ = ch; *p1++ = ch;
*p1 = 0; *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('@'); sal_Int32 l = aExpr.indexOf('@');
m_aHost = aExpr.copy(1+l); m_aHost = aExpr.copy(1+l);
...@@ -203,26 +204,26 @@ void FTPURL::parse(const OUString& url) ...@@ -203,26 +204,26 @@ void FTPURL::parse(const OUString& url)
} }
while(ch) { // now determine the pathsegments ... while(ch) { // now determine the pathsegments ...
p1 = buffer; p1 = buffer.get();
while((ch = *p2++) != '/' && ch) while((ch = *p2++) != '/' && ch)
*p1++ = ch; *p1++ = ch;
*p1 = 0; *p1 = 0;
if(buffer[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(); m_aPathSegmentVec.pop_back();
else if(strcmp(buffer,".") == 0) else if(strcmp(buffer.get(),".") == 0)
; // Ignore ; // Ignore
else else
// This is a legal name. // This is a legal name.
m_aPathSegmentVec.push_back( m_aPathSegmentVec.push_back(
OUString(buffer, OUString(buffer.get(),
strlen(buffer), strlen(buffer.get()),
RTL_TEXTENCODING_UTF8)); RTL_TEXTENCODING_UTF8));
} }
} }
delete[] buffer; buffer.reset();
if(m_bShowPassword) if(m_bShowPassword)
m_pFCP->setHost(m_aHost, m_pFCP->setHost(m_aHost,
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "LockSequence.hxx" #include "LockSequence.hxx"
#include "LockEntrySequence.hxx" #include "LockEntrySequence.hxx"
#include "UCBDeadPropertyValue.hxx" #include "UCBDeadPropertyValue.hxx"
#include <boost/scoped_array.hpp>
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::ucb; using namespace com::sun::star::ucb;
...@@ -248,7 +249,7 @@ NeonPropFindRequest::NeonPropFindRequest( HttpSession* inSession, ...@@ -248,7 +249,7 @@ NeonPropFindRequest::NeonPropFindRequest( HttpSession* inSession,
int thePropCount = inPropNames.size(); int thePropCount = inPropNames.size();
if ( thePropCount > 0 ) if ( thePropCount > 0 )
{ {
NeonPropName* thePropNames = new NeonPropName[ thePropCount + 1 ]; boost::scoped_array<NeonPropName> thePropNames(new NeonPropName[ thePropCount + 1 ]);
int theIndex; int theIndex;
for ( theIndex = 0; theIndex < thePropCount; theIndex ++ ) for ( theIndex = 0; theIndex < thePropCount; theIndex ++ )
...@@ -265,15 +266,13 @@ NeonPropFindRequest::NeonPropFindRequest( HttpSession* inSession, ...@@ -265,15 +266,13 @@ NeonPropFindRequest::NeonPropFindRequest( HttpSession* inSession,
nError = ne_simple_propfind( inSession, nError = ne_simple_propfind( inSession,
inPath, inPath,
inDepth, inDepth,
thePropNames, thePropNames.get(),
NPFR_propfind_results, NPFR_propfind_results,
&ioResources ); &ioResources );
} }
for ( theIndex = 0; theIndex < thePropCount; theIndex ++ ) for ( theIndex = 0; theIndex < thePropCount; theIndex ++ )
free( (void *)thePropNames[ theIndex ].name ); free( (void *)thePropNames[ theIndex ].name );
delete [] thePropNames;
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment