Avoid possible memory leaks in case of exceptions
Change-Id: Ibadadacbe09a93e7d7a7210868c52a8fa582d427
This commit is contained in:
@@ -36,6 +36,8 @@
|
|||||||
#include <rtl/bootstrap.hxx>
|
#include <rtl/bootstrap.hxx>
|
||||||
|
|
||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
|
#include <boost/scoped_array.hpp>
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
|
||||||
IndexerPreProcessor::IndexerPreProcessor
|
IndexerPreProcessor::IndexerPreProcessor
|
||||||
( const std::string& aModuleName, const fs::path& fsIndexBaseDir,
|
( const std::string& aModuleName, const fs::path& fsIndexBaseDir,
|
||||||
@@ -946,9 +948,8 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp
|
|||||||
xmlSetStructuredErrorFunc( NULL, (xmlStructuredErrorFunc)StructuredXMLErrorFunction );
|
xmlSetStructuredErrorFunc( NULL, (xmlStructuredErrorFunc)StructuredXMLErrorFunction );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HelpLinker* pHelpLinker = new HelpLinker();
|
boost::scoped_ptr<HelpLinker> pHelpLinker(new HelpLinker());
|
||||||
pHelpLinker->main( args, &aStdStrExtensionPath, &aStdStrDestination, &aOfficeHelpPath );
|
pHelpLinker->main( args, &aStdStrExtensionPath, &aStdStrDestination, &aOfficeHelpPath );
|
||||||
delete pHelpLinker;
|
|
||||||
}
|
}
|
||||||
catch( const HelpProcessingException& e )
|
catch( const HelpProcessingException& e )
|
||||||
{
|
{
|
||||||
@@ -980,14 +981,14 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp
|
|||||||
aFileStatus.isValid( osl_FileStatus_Mask_FileSize ) )
|
aFileStatus.isValid( osl_FileStatus_Mask_FileSize ) )
|
||||||
{
|
{
|
||||||
sal_uInt64 ret, len = aFileStatus.getFileSize();
|
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 );
|
osl::File aFile( aTreeFileURL );
|
||||||
aFile.open( osl_File_OpenFlag_Read );
|
aFile.open( osl_File_OpenFlag_Read );
|
||||||
aFile.read( s, len, ret );
|
aFile.read( s.get(), len, ret );
|
||||||
aFile.close();
|
aFile.close();
|
||||||
|
|
||||||
XML_Parser parser = XML_ParserCreate( 0 );
|
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)
|
if (XML_STATUS_ERROR == parsed)
|
||||||
{
|
{
|
||||||
@@ -1000,7 +1001,6 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp
|
|||||||
}
|
}
|
||||||
|
|
||||||
XML_ParserFree( parser );
|
XML_ParserFree( parser );
|
||||||
delete[] s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include <HelpLinker.hxx>
|
#include <HelpLinker.hxx>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sal/main.h>
|
#include <sal/main.h>
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
|
||||||
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
|
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
@@ -28,9 +29,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
|
|||||||
args.push_back(std::string(argv[i]));
|
args.push_back(std::string(argv[i]));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HelpLinker* pHelpLinker = new HelpLinker();
|
boost::scoped_ptr<HelpLinker> pHelpLinker(new HelpLinker());
|
||||||
pHelpLinker->main( args );
|
pHelpLinker->main( args );
|
||||||
delete pHelpLinker;
|
|
||||||
}
|
}
|
||||||
catch( const HelpProcessingException& e )
|
catch( const HelpProcessingException& e )
|
||||||
{
|
{
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <data/numberchar.h>
|
#include <data/numberchar.h>
|
||||||
#include <comphelper/string.hxx>
|
#include <comphelper/string.hxx>
|
||||||
#include <cppuhelper/supportsservice.hxx>
|
#include <cppuhelper/supportsservice.hxx>
|
||||||
|
#include <boost/scoped_array.hpp>
|
||||||
|
|
||||||
using namespace ::com::sun::star::uno;
|
using namespace ::com::sun::star::uno;
|
||||||
using namespace ::com::sun::star::lang;
|
using namespace ::com::sun::star::lang;
|
||||||
@@ -172,8 +173,8 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
|
|||||||
if (nCount > 0)
|
if (nCount > 0)
|
||||||
{
|
{
|
||||||
const sal_Unicode *str = inStr.getStr() + startPos;
|
const sal_Unicode *str = inStr.getStr() + startPos;
|
||||||
sal_Unicode *newStr = new sal_Unicode[nCount * 2 + 1];
|
boost::scoped_array<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> srcStr(new sal_Unicode[nCount + 1]); // for keeping number without comma
|
||||||
sal_Int32 i, len = 0, count = 0;
|
sal_Int32 i, len = 0, count = 0;
|
||||||
|
|
||||||
if (useOffset)
|
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]) {
|
end <= len; begin = end, end += number->multiplierExponent[0]) {
|
||||||
if (end == 0) continue;
|
if (end == 0) continue;
|
||||||
sal_Int32 _count = count;
|
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);
|
end == len ? -1 : 0, offset, useOffset, i - len + startPos, number, numberChar);
|
||||||
if (count > 0 && number->multiplierExponent[number->exponentCount-1] == 1 &&
|
if (count > 0 && number->multiplierExponent[number->exponentCount-1] == 1 &&
|
||||||
newStr[count-1] == numberChar[0])
|
newStr[count-1] == numberChar[0])
|
||||||
@@ -238,12 +239,9 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] srcStr;
|
|
||||||
|
|
||||||
if (useOffset)
|
if (useOffset)
|
||||||
offset.realloc(count);
|
offset.realloc(count);
|
||||||
aRet = OUString(newStr, count);
|
aRet = OUString(newStr.get(), count);
|
||||||
delete[] newStr;
|
|
||||||
}
|
}
|
||||||
return aRet;
|
return aRet;
|
||||||
}
|
}
|
||||||
@@ -308,7 +306,7 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
|
|||||||
|
|
||||||
if (nCount > 0) {
|
if (nCount > 0) {
|
||||||
const sal_Unicode *str = inStr.getStr() + startPos;
|
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)
|
if (useOffset)
|
||||||
offset.realloc( nCount * MultiplierExponent_7_CJK[0] + 1 );
|
offset.realloc( nCount * MultiplierExponent_7_CJK[0] + 1 );
|
||||||
sal_Int32 count = 0, index;
|
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];
|
index = MultiplierExponent_7_CJK[index % ExponentCount_7_CJK];
|
||||||
NativeToAscii_numberMaker(
|
NativeToAscii_numberMaker(
|
||||||
sal::static_int_cast<sal_Int16>( index ), sal::static_int_cast<sal_Int16>( index ),
|
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);
|
numberChar, multiplierChar);
|
||||||
} else {
|
} else {
|
||||||
if ((index = numberChar.indexOf(str[i])) >= 0)
|
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++)
|
for (i = 0; i < count; i++)
|
||||||
offset[i] += startPos;
|
offset[i] += startPos;
|
||||||
}
|
}
|
||||||
aRet = OUString(newStr, count);
|
aRet = OUString(newStr.get(), count);
|
||||||
delete[] newStr;
|
|
||||||
}
|
}
|
||||||
return aRet;
|
return aRet;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
|
#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
|
||||||
#include <rtl/ustrbuf.hxx>
|
#include <rtl/ustrbuf.hxx>
|
||||||
#include <unicode/uchar.h>
|
#include <unicode/uchar.h>
|
||||||
|
#include <boost/scoped_array.hpp>
|
||||||
|
|
||||||
using namespace com::sun::star::lang;
|
using namespace com::sun::star::lang;
|
||||||
using namespace com::sun::star::i18n;
|
using namespace com::sun::star::i18n;
|
||||||
@@ -166,7 +167,7 @@ TextConversion_ko::getCharConversions(const OUString& aText, sal_Int32 nStartPos
|
|||||||
}
|
}
|
||||||
} else if (! toHanja && getHanja2HangulIndex && getHanja2HangulData)
|
} 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;
|
sal_Int32 count = 0;
|
||||||
while (count < nLength)
|
while (count < nLength)
|
||||||
{
|
{
|
||||||
@@ -183,9 +184,8 @@ TextConversion_ko::getCharConversions(const OUString& aText, sal_Int32 nStartPos
|
|||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
output.realloc(1);
|
output.realloc(1);
|
||||||
output[0] = OUString(newStr, count);
|
output[0] = OUString(newStr.get(), count);
|
||||||
}
|
}
|
||||||
delete[] newStr;
|
|
||||||
}
|
}
|
||||||
#if defined(DISABLE_DYNLOADING)
|
#if defined(DISABLE_DYNLOADING)
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
|
#include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
|
||||||
#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
|
#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
|
||||||
#include <comphelper/string.hxx>
|
#include <comphelper/string.hxx>
|
||||||
|
#include <boost/scoped_array.hpp>
|
||||||
|
|
||||||
using namespace com::sun::star::lang;
|
using namespace com::sun::star::lang;
|
||||||
using namespace com::sun::star::i18n;
|
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.
|
if ((!wordData || !index || !entry) && !xCDL.is()) // no word mapping defined, do char2char conversion.
|
||||||
return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
|
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;
|
sal_Int32 currPos = 0, count = 0;
|
||||||
while (currPos < nLength) {
|
while (currPos < nLength) {
|
||||||
sal_Int32 len = nLength - currPos;
|
sal_Int32 len = nLength - currPos;
|
||||||
@@ -259,8 +260,7 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
|
|||||||
}
|
}
|
||||||
if (offset.getLength() > 0)
|
if (offset.getLength() > 0)
|
||||||
offset.realloc(one2one ? 0 : count);
|
offset.realloc(one2one ? 0 : count);
|
||||||
OUString aRet(newStr, count);
|
OUString aRet(newStr.get(), count);
|
||||||
delete[] newStr;
|
|
||||||
return aRet;
|
return aRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#define TRANSLITERATION_ALL
|
#define TRANSLITERATION_ALL
|
||||||
#include "transliteration_body.hxx"
|
#include "transliteration_body.hxx"
|
||||||
|
#include <boost/scoped_array.hpp>
|
||||||
|
|
||||||
using namespace ::com::sun::star::uno;
|
using namespace ::com::sun::star::uno;
|
||||||
using namespace ::com::sun::star::lang;
|
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,
|
// Allocate the max possible buffer. Try to use stack instead of heap,
|
||||||
// which would have to be reallocated most times anyways.
|
// which would have to be reallocated most times anyways.
|
||||||
const sal_Int32 nLocalBuf = 2048;
|
const sal_Int32 nLocalBuf = 2048;
|
||||||
sal_Unicode aLocalBuf[ nLocalBuf * NMAPPINGMAX ], *out = aLocalBuf, *pHeapBuf = NULL;
|
sal_Unicode aLocalBuf[ nLocalBuf * NMAPPINGMAX ], *out = aLocalBuf;
|
||||||
if ( nCount > nLocalBuf )
|
boost::scoped_array<sal_Unicode> pHeapBuf;
|
||||||
out = pHeapBuf = new sal_Unicode[ nCount * NMAPPINGMAX ];
|
if ( nCount > nLocalBuf ) {
|
||||||
|
pHeapBuf.reset(new sal_Unicode[ nCount * NMAPPINGMAX ]);
|
||||||
|
out = pHeapBuf.get();
|
||||||
|
}
|
||||||
|
|
||||||
sal_Int32 j = 0;
|
sal_Int32 j = 0;
|
||||||
for ( sal_Int32 i = 0; i < nCount; i++)
|
for ( sal_Int32 i = 0; i < nCount; i++)
|
||||||
@@ -174,8 +178,6 @@ Transliteration_body::transliterate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
OUString aRet( out, j );
|
OUString aRet( out, j );
|
||||||
if ( pHeapBuf )
|
|
||||||
delete [] pHeapBuf;
|
|
||||||
return aRet;
|
return aRet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user