summaryrefslogtreecommitdiff
path: root/ucb/source/ucp
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-07-24 23:09:24 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-07-25 10:09:15 +0900
commita8b395bff2111d7bf086b4cb44081dce10cca364 (patch)
treeec4a4ebebe94fcd58b9c8508b8c403e32a2a9cfc /ucb/source/ucp
parent4f2f53e267956e68fac768391c9b83d45adbc29f (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: I9983e858c4e634b4cac8ad42fa9b06b7ccc167d6
Diffstat (limited to 'ucb/source/ucp')
-rw-r--r--ucb/source/ucp/cmis/cmis_repo_content.cxx8
-rw-r--r--ucb/source/ucp/file/filstr.cxx11
-rw-r--r--ucb/source/ucp/ftp/ftpurl.cxx19
-rw-r--r--ucb/source/ucp/webdav-neon/NeonPropFindRequest.cxx7
4 files changed, 22 insertions, 23 deletions
diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx
index 4d2504978388..ea99c3509063 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 bd8ee9ba3220..95391728d21c 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 6b176a524c47..1fb36be4a2ae 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@host:port"
+ char *p1 = buffer.get(); // determine "username:password@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 c5945f27600c..73b6c7c5df32 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
{