summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-24 00:09:19 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-24 00:13:28 +0900
commit1ec836760853e9e220d471cf39f2533f0828f00e (patch)
treeaa481fb529d129a16af492818f63858a1af757d8 /sal
parent2ea006fb605b886f9c9426783e4edf0de46c9af8 (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: I047fd88a89900153089a55b6af123f11fb8bde55
Diffstat (limited to 'sal')
-rw-r--r--sal/cppunittester/cppunittester.cxx10
-rw-r--r--sal/textenc/tencinfo.cxx23
2 files changed, 14 insertions, 19 deletions
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index f4c2fc6c299a..f8b9d6459502 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -47,6 +47,7 @@
#include "boost/noncopyable.hpp"
#include "boost/ptr_container/ptr_vector.hpp"
+#include <boost/scoped_array.hpp>
#include "boost/static_assert.hpp"
namespace {
@@ -108,9 +109,9 @@ class EyecatcherListener
public:
void startTest( CppUnit::Test* test) SAL_OVERRIDE
{
- char* tn = new char [ test->getName().length() + 2 ];
- strcpy(tn, test->getName().c_str());
- int len = strlen(tn);
+ boost::scoped_array<char> tn(new char [ test->getName().length() + 2 ]);
+ strcpy(tn.get(), test->getName().c_str());
+ int len = strlen(tn.get());
for(int i = 0; i < len; i++)
{
if(!isalnum(tn[i]))
@@ -120,8 +121,7 @@ public:
}
tn[len] = '_';
tn[len + 1] = 0;
- setenv("LO_TESTNAME", tn, true);
- delete[] tn;
+ setenv("LO_TESTNAME", tn.get(), true);
}
void endTest( CppUnit::Test* /* test */ ) SAL_OVERRIDE
diff --git a/sal/textenc/tencinfo.cxx b/sal/textenc/tencinfo.cxx
index ccbfe4037d10..0aaa2ff0c446 100644
--- a/sal/textenc/tencinfo.cxx
+++ b/sal/textenc/tencinfo.cxx
@@ -26,6 +26,7 @@
#include "gettextencodingdata.hxx"
#include "tenchelp.hxx"
+#include <boost/scoped_array.hpp>
sal_Bool SAL_CALL rtl_isOctetTextEncoding(rtl_TextEncoding nEncoding)
{
@@ -407,20 +408,19 @@ rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromUnixCharset( const char* pUnixC
};
rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
- char* pBuf;
char* pTempBuf;
sal_uInt32 nBufLen = strlen( pUnixCharset )+1;
const char* pFirstPart;
const char* pSecondPart;
/* Alloc Buffer and map to lower case */
- pBuf = new char[nBufLen];
- Impl_toAsciiLower( pUnixCharset, pBuf );
+ boost::scoped_array<char> pBuf(new char[nBufLen]);
+ Impl_toAsciiLower( pUnixCharset, pBuf.get() );
/* Search FirstPart */
- pFirstPart = pBuf;
+ pFirstPart = pBuf.get();
pSecondPart = NULL;
- pTempBuf = pBuf;
+ pTempBuf = pBuf.get();
while ( *pTempBuf )
{
if ( *pTempBuf == '-' )
@@ -463,8 +463,6 @@ rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromUnixCharset( const char* pUnixC
}
}
- delete[] pBuf;
-
return eEncoding;
}
@@ -740,18 +738,17 @@ rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromMimeCharset( const char* pMimeC
};
rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
- char* pBuf;
const ImplStrCharsetDef* pData = aVIPMimeCharsetTab;
sal_uInt32 nBufLen = strlen( pMimeCharset )+1;
/* Alloc Buffer and map to lower case and remove non alphanumeric chars */
- pBuf = new char[nBufLen];
- Impl_toAsciiLowerAndRemoveNonAlphanumeric( pMimeCharset, pBuf );
+ boost::scoped_array<char> pBuf(new char[nBufLen]);
+ Impl_toAsciiLowerAndRemoveNonAlphanumeric( pMimeCharset, pBuf.get() );
/* Search for equal in the VIP table */
while ( pData->mpCharsetStr )
{
- if ( strcmp( pBuf, pData->mpCharsetStr ) == 0 )
+ if ( strcmp( pBuf.get(), pData->mpCharsetStr ) == 0 )
{
eEncoding = pData->meTextEncoding;
break;
@@ -766,7 +763,7 @@ rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromMimeCharset( const char* pMimeC
pData = aMimeCharsetTab;
while ( pData->mpCharsetStr )
{
- if ( Impl_matchString( pBuf, pData->mpCharsetStr ) )
+ if ( Impl_matchString( pBuf.get(), pData->mpCharsetStr ) )
{
eEncoding = pData->meTextEncoding;
break;
@@ -776,8 +773,6 @@ rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromMimeCharset( const char* pMimeC
}
}
- delete[] pBuf;
-
return eEncoding;
}