[Libreoffice-commits] core.git: jvmfwk/source l10ntools/source lingucomponent/source
Takeshi Abe
tabe at fixedpoint.jp
Mon Apr 21 06:31:41 PDT 2014
jvmfwk/source/fwkutil.cxx | 13 +++-----
l10ntools/source/xrmmerge.cxx | 8 ++--
lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx | 29 +++++-------------
3 files changed, 19 insertions(+), 31 deletions(-)
New commits:
commit 1a5457a11c062be8c41cc00813c092b78aa42b8b
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Mon Apr 21 22:29:09 2014 +0900
Avoid possible memory leaks in case of exceptions
Change-Id: I4b2b439615db0ff4598f405d1e339eebbff7ae91
diff --git a/jvmfwk/source/fwkutil.cxx b/jvmfwk/source/fwkutil.cxx
index d7ca9ff..4edb4e8 100644
--- a/jvmfwk/source/fwkutil.cxx
+++ b/jvmfwk/source/fwkutil.cxx
@@ -46,6 +46,7 @@
#include "framework.hxx"
#include "fwkutil.hxx"
+#include <boost/scoped_array.hpp>
using namespace osl;
@@ -114,10 +115,10 @@ rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData)
static const char EncodingTable[] =
{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
sal_Int32 lenRaw = rawData.getLength();
- char* pBuf = new char[lenRaw * 2];
+ boost::scoped_array<char> pBuf(new char[lenRaw * 2]);
const sal_Int8* arRaw = rawData.getConstArray();
- char* pCurBuf = pBuf;
+ char* pCurBuf = pBuf.get();
for (int i = 0; i < lenRaw; i++)
{
unsigned char curChar = arRaw[i];
@@ -133,8 +134,7 @@ rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData)
pCurBuf++;
}
- rtl::ByteSequence ret((sal_Int8*) pBuf, lenRaw * 2);
- delete [] pBuf;
+ rtl::ByteSequence ret((sal_Int8*) pBuf.get(), lenRaw * 2);
return ret;
}
@@ -144,7 +144,7 @@ rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data)
{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
sal_Int32 lenData = data.getLength();
sal_Int32 lenBuf = lenData / 2; //always divisable by two
- unsigned char* pBuf = new unsigned char[lenBuf];
+ boost::scoped_array<unsigned char> pBuf(new unsigned char[lenBuf]);
const sal_Int8* pData = data.getConstArray();
for (sal_Int32 i = 0; i < lenBuf; i++)
{
@@ -173,8 +173,7 @@ rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data)
}
pBuf[i] = nibble;
}
- rtl::ByteSequence ret((sal_Int8*) pBuf, lenBuf );
- delete [] pBuf;
+ rtl::ByteSequence ret((sal_Int8*) pBuf.get(), lenBuf );
return ret;
}
diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx
index f3705fa..37190fb 100644
--- a/l10ntools/source/xrmmerge.cxx
+++ b/l10ntools/source/xrmmerge.cxx
@@ -33,6 +33,7 @@
#include <iostream>
#include <fstream>
#include <vector>
+#include <boost/scoped_array.hpp>
using namespace std;
@@ -327,13 +328,12 @@ void XRMResExport::WorkOnDesc(
ifstream file (sDescFileName.getStr(), ios::in|ios::binary|ios::ate);
if (file.is_open()) {
int size = static_cast<int>(file.tellg());
- char* memblock = new char [size+1];
+ boost::scoped_array<char> memblock(new char [size+1]);
file.seekg (0, ios::beg);
- file.read (memblock, size);
+ file.read (memblock.get(), size);
file.close();
memblock[size] = '\0';
- rText = OString(memblock);
- delete[] memblock;
+ rText = OString(memblock.get());
}
WorkOnText( rOpenTag, rText );
EndOfText( rOpenTag, rOpenTag );
diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
index b74b2da..40f7dd2 100644
--- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
+++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
@@ -47,6 +47,7 @@
#include <list>
#include <set>
+#include <boost/scoped_array.hpp>
using namespace utl;
using namespace osl;
@@ -253,8 +254,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
int nHyphenationPosAlt = -1;
int nHyphenationPosAltHyph = -1;
int wordlen;
- char *hyphens;
- char *lcword;
int k = 0;
PropertyHelper_Hyphenation& rHelper = GetPropHelper();
@@ -341,15 +340,15 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
OString encWord(OU2ENC(nTerm,eEnc));
wordlen = encWord.getLength();
- lcword = new char[wordlen + 1];
- hyphens = new char[wordlen + 5];
+ boost::scoped_array<char> lcword(new char[wordlen + 1]);
+ boost::scoped_array<char> hyphens(new char[wordlen + 5]);
char ** rep = NULL; // replacements of discretionary hyphenation
int * pos = NULL; // array of [hyphenation point] minus [deletion position]
int * cut = NULL; // length of deletions in original word
// copy converted word into simple char buffer
- strcpy(lcword,encWord.getStr());
+ strcpy(lcword.get(),encWord.getStr());
// now strip off any ending periods
int n = wordlen-1;
@@ -358,15 +357,13 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
n++;
if (n > 0)
{
- const bool bFailed = 0 != hnj_hyphen_hyphenate3( dict, lcword, n, hyphens, NULL,
+ const bool bFailed = 0 != hnj_hyphen_hyphenate3( dict, lcword.get(), n, hyphens.get(), NULL,
&rep, &pos, &cut, minLead, minTrail,
Max(dict->clhmin, Max(dict->clhmin, 2) + Max(0, minLead - Max(dict->lhmin, 2))),
Max(dict->crhmin, Max(dict->crhmin, 2) + Max(0, minTrail - Max(dict->rhmin, 2))) );
if (bFailed)
{
// whoops something did not work
- delete[] hyphens;
- delete[] lcword;
if (rep)
{
for(int j = 0; j < n; j++)
@@ -480,8 +477,6 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
}
}
- delete[] lcword;
- delete[] hyphens;
if (rep)
{
for(int j = 0; j < n; j++)
@@ -603,14 +598,14 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
OString encWord(OU2ENC(nTerm,eEnc));
int wordlen = encWord.getLength();
- char *lcword = new char[wordlen+1];
- char *hyphens = new char[wordlen+5];
+ boost::scoped_array<char> lcword(new char[wordlen+1]);
+ boost::scoped_array<char> hyphens(new char[wordlen+5]);
char ** rep = NULL; // replacements of discretionary hyphenation
int * pos = NULL; // array of [hyphenation point] minus [deletion position]
int * cut = NULL; // length of deletions in original word
// copy converted word into simple char buffer
- strcpy(lcword,encWord.getStr());
+ strcpy(lcword.get(),encWord.getStr());
// first remove any trailing periods
int n = wordlen-1;
@@ -619,15 +614,12 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
n++;
if (n > 0)
{
- const bool bFailed = 0 != hnj_hyphen_hyphenate3(dict, lcword, n, hyphens, NULL,
+ const bool bFailed = 0 != hnj_hyphen_hyphenate3(dict, lcword.get(), n, hyphens.get(), NULL,
&rep, &pos, &cut, minLead, minTrail,
Max(dict->clhmin, Max(dict->clhmin, 2) + Max(0, minLead - Max(dict->lhmin, 2))),
Max(dict->crhmin, Max(dict->crhmin, 2) + Max(0, minTrail - Max(dict->rhmin, 2))) );
if (bFailed)
{
- delete[] hyphens;
- delete[] lcword;
-
if (rep)
{
for(int j = 0; j < n; j++)
@@ -678,9 +670,6 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
Reference< XPossibleHyphens > xRes = PossibleHyphens::CreatePossibleHyphens(
aWord, LinguLocaleToLanguage( aLocale ), hyphenatedWord, aHyphPos);
- delete[] hyphens;
- delete[] lcword;
-
if (rep)
{
for(int j = 0; j < n; j++)
More information about the Libreoffice-commits
mailing list