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

Avoid possible memory leaks in case of exceptions

Change-Id: Ibadadacbe09a93e7d7a7210868c52a8fa582d427
üst 326f8dc3
......@@ -36,6 +36,8 @@
#include <rtl/bootstrap.hxx>
#include <expat.h>
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
IndexerPreProcessor::IndexerPreProcessor
( const std::string& aModuleName, const fs::path& fsIndexBaseDir,
......@@ -946,9 +948,8 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp
xmlSetStructuredErrorFunc( NULL, (xmlStructuredErrorFunc)StructuredXMLErrorFunction );
try
{
HelpLinker* pHelpLinker = new HelpLinker();
boost::scoped_ptr<HelpLinker> pHelpLinker(new HelpLinker());
pHelpLinker->main( args, &aStdStrExtensionPath, &aStdStrDestination, &aOfficeHelpPath );
delete pHelpLinker;
}
catch( const HelpProcessingException& e )
{
......@@ -980,14 +981,14 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp
aFileStatus.isValid( osl_FileStatus_Mask_FileSize ) )
{
sal_uInt64 ret, len = aFileStatus.getFileSize();
char* s = new char[ int(len) ]; // the buffer to hold the installed files
boost::scoped_array<char> s(new char[ int(len) ]); // the buffer to hold the installed files
osl::File aFile( aTreeFileURL );
aFile.open( osl_File_OpenFlag_Read );
aFile.read( s, len, ret );
aFile.read( s.get(), len, ret );
aFile.close();
XML_Parser parser = XML_ParserCreate( 0 );
XML_Status parsed = XML_Parse( parser, s, int( len ), true );
XML_Status parsed = XML_Parse( parser, s.get(), int( len ), true );
if (XML_STATUS_ERROR == parsed)
{
......@@ -1000,7 +1001,6 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp
}
XML_ParserFree( parser );
delete[] s;
}
return bSuccess;
......
......@@ -21,6 +21,7 @@
#include <HelpLinker.hxx>
#include <iostream>
#include <sal/main.h>
#include <boost/scoped_ptr.hpp>
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
std::vector<std::string> args;
......@@ -28,9 +29,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
args.push_back(std::string(argv[i]));
try
{
HelpLinker* pHelpLinker = new HelpLinker();
boost::scoped_ptr<HelpLinker> pHelpLinker(new HelpLinker());
pHelpLinker->main( args );
delete pHelpLinker;
}
catch( const HelpProcessingException& e )
{
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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;
}
}
......
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