summaryrefslogtreecommitdiff
path: root/lingucomponent
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-21 22:29:09 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-21 22:29:09 +0900
commit1a5457a11c062be8c41cc00813c092b78aa42b8b (patch)
tree22bf3a3929b91e8e9629bd43ea5e64f791e673dd /lingucomponent
parentaa8820bdc2c5d22c46119b2afcea0466951745de (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: I4b2b439615db0ff4598f405d1e339eebbff7ae91
Diffstat (limited to 'lingucomponent')
-rw-r--r--lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx29
1 files changed, 9 insertions, 20 deletions
diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
index b74b2dac65bb..40f7dd279168 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++)