summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-17 10:56:03 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-17 10:57:00 +0900
commit6a964dcf0fe3b9258d07391ada0f0d245b1f7cec (patch)
treeb9af585607c69e5f8ccd227931eab42a4f9b824c /i18npool
parent326f8dc37bc11591e7d683b21085da7ee15b8072 (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: Ibadadacbe09a93e7d7a7210868c52a8fa582d427
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/nativenumber/nativenumbersupplier.cxx19
-rw-r--r--i18npool/source/textconversion/textconversion_ko.cxx6
-rw-r--r--i18npool/source/textconversion/textconversion_zh.cxx6
-rw-r--r--i18npool/source/transliteration/transliteration_body.cxx12
4 files changed, 21 insertions, 22 deletions
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index 3883840ab167..8cb9c166c20e 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -25,6 +25,7 @@
#include <data/numberchar.h>
#include <comphelper/string.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <boost/scoped_array.hpp>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
@@ -172,8 +173,8 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
if (nCount > 0)
{
const sal_Unicode *str = inStr.getStr() + startPos;
- sal_Unicode *newStr = new sal_Unicode[nCount * 2 + 1];
- sal_Unicode *srcStr = new sal_Unicode[nCount + 1]; // for keeping number without comma
+ boost::scoped_array<sal_Unicode> newStr(new sal_Unicode[nCount * 2 + 1]);
+ boost::scoped_array<sal_Unicode> srcStr(new sal_Unicode[nCount + 1]); // for keeping number without comma
sal_Int32 i, len = 0, count = 0;
if (useOffset)
@@ -200,7 +201,7 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
end <= len; begin = end, end += number->multiplierExponent[0]) {
if (end == 0) continue;
sal_Int32 _count = count;
- notZero |= AsciiToNative_numberMaker(srcStr, begin, end - begin, newStr, count,
+ notZero |= AsciiToNative_numberMaker(srcStr.get(), begin, end - begin, newStr.get(), count,
end == len ? -1 : 0, offset, useOffset, i - len + startPos, number, numberChar);
if (count > 0 && number->multiplierExponent[number->exponentCount-1] == 1 &&
newStr[count-1] == numberChar[0])
@@ -238,12 +239,9 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
}
}
- delete[] srcStr;
-
if (useOffset)
offset.realloc(count);
- aRet = OUString(newStr, count);
- delete[] newStr;
+ aRet = OUString(newStr.get(), count);
}
return aRet;
}
@@ -308,7 +306,7 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
if (nCount > 0) {
const sal_Unicode *str = inStr.getStr() + startPos;
- sal_Unicode *newStr = new sal_Unicode[nCount * MultiplierExponent_7_CJK[0] + 2];
+ boost::scoped_array<sal_Unicode> newStr(new sal_Unicode[nCount * MultiplierExponent_7_CJK[0] + 2]);
if (useOffset)
offset.realloc( nCount * MultiplierExponent_7_CJK[0] + 1 );
sal_Int32 count = 0, index;
@@ -332,7 +330,7 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
index = MultiplierExponent_7_CJK[index % ExponentCount_7_CJK];
NativeToAscii_numberMaker(
sal::static_int_cast<sal_Int16>( index ), sal::static_int_cast<sal_Int16>( index ),
- str, i, nCount, newStr, count, offset, useOffset,
+ str, i, nCount, newStr.get(), count, offset, useOffset,
numberChar, multiplierChar);
} else {
if ((index = numberChar.indexOf(str[i])) >= 0)
@@ -366,8 +364,7 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
for (i = 0; i < count; i++)
offset[i] += startPos;
}
- aRet = OUString(newStr, count);
- delete[] newStr;
+ aRet = OUString(newStr.get(), count);
}
return aRet;
}
diff --git a/i18npool/source/textconversion/textconversion_ko.cxx b/i18npool/source/textconversion/textconversion_ko.cxx
index a658c3246771..16965f825635 100644
--- a/i18npool/source/textconversion/textconversion_ko.cxx
+++ b/i18npool/source/textconversion/textconversion_ko.cxx
@@ -26,6 +26,7 @@
#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
#include <rtl/ustrbuf.hxx>
#include <unicode/uchar.h>
+#include <boost/scoped_array.hpp>
using namespace com::sun::star::lang;
using namespace com::sun::star::i18n;
@@ -166,7 +167,7 @@ TextConversion_ko::getCharConversions(const OUString& aText, sal_Int32 nStartPos
}
} else if (! toHanja && getHanja2HangulIndex && getHanja2HangulData)
{
- sal_Unicode *newStr = new sal_Unicode[nLength+1];
+ boost::scoped_array<sal_Unicode> newStr(new sal_Unicode[nLength+1]);
sal_Int32 count = 0;
while (count < nLength)
{
@@ -183,9 +184,8 @@ TextConversion_ko::getCharConversions(const OUString& aText, sal_Int32 nStartPos
if (count > 0)
{
output.realloc(1);
- output[0] = OUString(newStr, count);
+ output[0] = OUString(newStr.get(), count);
}
- delete[] newStr;
}
#if defined(DISABLE_DYNLOADING)
#pragma GCC diagnostic pop
diff --git a/i18npool/source/textconversion/textconversion_zh.cxx b/i18npool/source/textconversion/textconversion_zh.cxx
index a4a4a1b81f64..db800f8a6031 100644
--- a/i18npool/source/textconversion/textconversion_zh.cxx
+++ b/i18npool/source/textconversion/textconversion_zh.cxx
@@ -26,6 +26,7 @@
#include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
#include <comphelper/string.hxx>
+#include <boost/scoped_array.hpp>
using namespace com::sun::star::lang;
using namespace com::sun::star::i18n;
@@ -164,7 +165,7 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
if ((!wordData || !index || !entry) && !xCDL.is()) // no word mapping defined, do char2char conversion.
return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
- sal_Unicode *newStr = new sal_Unicode[nLength * 2 + 1];
+ boost::scoped_array<sal_Unicode> newStr(new sal_Unicode[nLength * 2 + 1]);
sal_Int32 currPos = 0, count = 0;
while (currPos < nLength) {
sal_Int32 len = nLength - currPos;
@@ -259,8 +260,7 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
}
if (offset.getLength() > 0)
offset.realloc(one2one ? 0 : count);
- OUString aRet(newStr, count);
- delete[] newStr;
+ OUString aRet(newStr.get(), count);
return aRet;
}
diff --git a/i18npool/source/transliteration/transliteration_body.cxx b/i18npool/source/transliteration/transliteration_body.cxx
index f17fbafdbac9..da795fdbc205 100644
--- a/i18npool/source/transliteration/transliteration_body.cxx
+++ b/i18npool/source/transliteration/transliteration_body.cxx
@@ -32,6 +32,7 @@
#define TRANSLITERATION_ALL
#include "transliteration_body.hxx"
+#include <boost/scoped_array.hpp>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
@@ -154,9 +155,12 @@ Transliteration_body::transliterate(
// Allocate the max possible buffer. Try to use stack instead of heap,
// which would have to be reallocated most times anyways.
const sal_Int32 nLocalBuf = 2048;
- sal_Unicode aLocalBuf[ nLocalBuf * NMAPPINGMAX ], *out = aLocalBuf, *pHeapBuf = NULL;
- if ( nCount > nLocalBuf )
- out = pHeapBuf = new sal_Unicode[ nCount * NMAPPINGMAX ];
+ sal_Unicode aLocalBuf[ nLocalBuf * NMAPPINGMAX ], *out = aLocalBuf;
+ boost::scoped_array<sal_Unicode> pHeapBuf;
+ if ( nCount > nLocalBuf ) {
+ pHeapBuf.reset(new sal_Unicode[ nCount * NMAPPINGMAX ]);
+ out = pHeapBuf.get();
+ }
sal_Int32 j = 0;
for ( sal_Int32 i = 0; i < nCount; i++)
@@ -174,8 +178,6 @@ Transliteration_body::transliterate(
}
OUString aRet( out, j );
- if ( pHeapBuf )
- delete [] pHeapBuf;
return aRet;
}
}