helpcompiler/source/HelpLinker.cxx                       |   12 ++++-----
 helpcompiler/source/HelpLinker_main.cxx                  |    4 +--
 i18npool/source/nativenumber/nativenumbersupplier.cxx    |   19 ++++++---------
 i18npool/source/textconversion/textconversion_ko.cxx     |    6 ++--
 i18npool/source/textconversion/textconversion_zh.cxx     |    6 ++--
 i18npool/source/transliteration/transliteration_body.cxx |   12 +++++----
 6 files changed, 29 insertions(+), 30 deletions(-)

New commits:
commit 6a964dcf0fe3b9258d07391ada0f0d245b1f7cec
Author: Takeshi Abe <t...@fixedpoint.jp>
Date:   Thu Apr 17 10:56:03 2014 +0900

    Avoid possible memory leaks in case of exceptions
    
    Change-Id: Ibadadacbe09a93e7d7a7210868c52a8fa582d427

diff --git a/helpcompiler/source/HelpLinker.cxx 
b/helpcompiler/source/HelpLinker.cxx
index 3e1cfd4..f98c9a2 100644
--- a/helpcompiler/source/HelpLinker.cxx
+++ b/helpcompiler/source/HelpLinker.cxx
@@ -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;
diff --git a/helpcompiler/source/HelpLinker_main.cxx 
b/helpcompiler/source/HelpLinker_main.cxx
index 8390683..dd22eb9 100644
--- a/helpcompiler/source/HelpLinker_main.cxx
+++ b/helpcompiler/source/HelpLinker_main.cxx
@@ -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 )
     {
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx 
b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index 3883840..8cb9c16 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 a658c32..16965f8 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 a4a4a1b..db800f8 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 f17fbaf..da795fd 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;
     }
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to