[Libreoffice-commits] core.git: cui/source dbaccess/source desktop/source editeng/source

Takeshi Abe tabe at fixedpoint.jp
Fri Mar 28 03:22:27 PDT 2014


 cui/source/tabpages/numfmt.cxx                              |    8 ++---
 dbaccess/source/ui/misc/TokenWriter.cxx                     |   18 ++++--------
 desktop/source/app/officeipcthread.cxx                      |    6 ++--
 editeng/source/accessibility/AccessibleEditableTextPara.cxx |    4 +-
 4 files changed, 16 insertions(+), 20 deletions(-)

New commits:
commit e3bd2ee4e00185d6e0e57aba7046634142d614b8
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Fri Mar 28 19:17:53 2014 +0900

    Avoid possible resource leaks by boost::scoped_array
    
    Change-Id: Ie20fc857f19f74aaccb546f9bfa11a7a657d3e8a

diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index 837f18c..550711e 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -41,6 +41,7 @@
 #include "svx/flagsdef.hxx"
 #include <vector>
 #include <com/sun/star/lang/XServiceInfo.hpp>
+#include <boost/scoped_array.hpp>
 
 using ::com::sun::star::uno::Reference;
 using ::com::sun::star::lang::XServiceInfo;
@@ -736,10 +737,10 @@ bool SvxNumberFormatTabPage::FillItemSet( SfxItemSet& rCoreAttrs )
 
         if ( nDelCount > 0 )
         {
-            sal_uInt32*         pDelArr = new sal_uInt32[nDelCount];
+            boost::scoped_array<sal_uInt32> pDelArr(new sal_uInt32[nDelCount]);
 
-            pNumFmtShell->GetUpdateData( pDelArr, nDelCount );
-            pNumItem->SetDelFormatArray( pDelArr, nDelCount );
+            pNumFmtShell->GetUpdateData( pDelArr.get(), nDelCount );
+            pNumItem->SetDelFormatArray( pDelArr.get(), nDelCount );
 
             if(bNumItemFlag==sal_True)
             {
@@ -755,7 +756,6 @@ bool SvxNumberFormatTabPage::FillItemSet( SfxItemSet& rCoreAttrs )
                 if ( pDocSh )
                     pDocSh->PutItem( *pNumItem );
             }
-            delete [] pDelArr;
         }
 
 
diff --git a/dbaccess/source/ui/misc/TokenWriter.cxx b/dbaccess/source/ui/misc/TokenWriter.cxx
index cda597a..22dde9d 100644
--- a/dbaccess/source/ui/misc/TokenWriter.cxx
+++ b/dbaccess/source/ui/misc/TokenWriter.cxx
@@ -56,6 +56,7 @@
 #include <svtools/htmlcfg.hxx>
 #include <connectivity/formattedcolumnvalue.hxx>
 #include <unotools/syslocale.hxx>
+#include <boost/scoped_array.hpp>
 
 using namespace dbaui;
 using namespace dbtools;
@@ -453,7 +454,7 @@ sal_Bool ORTFImportExport::Write()
         m_pStream->WriteChar( '{' ).WriteCharPtr( SAL_NEWLINE_STRING );
         m_pStream->WriteCharPtr( aTRRH );
 
-        OString* pHorzChar = new OString[nCount];
+        boost::scoped_array<OString> pHorzChar(new OString[nCount]);
 
         for ( sal_Int32 i=1; i <= nCount; ++i )
         {
@@ -527,7 +528,7 @@ sal_Bool ORTFImportExport::Write()
                 }
 
                 if ( bContinue )
-                    appendRow( pHorzChar, nCount, k, kk );
+                    appendRow( pHorzChar.get(), nCount, k, kk );
             }
         }
         else
@@ -535,10 +536,9 @@ sal_Bool ORTFImportExport::Write()
             m_xResultSet->beforeFirst(); // set back before the first row
             while(m_xResultSet->next())
             {
-                appendRow(pHorzChar,nCount,k,kk);
+                appendRow(pHorzChar.get(),nCount,k,kk);
             }
         }
-        delete [] pHorzChar;
     }
 
     m_pStream->WriteChar( '}' ).WriteCharPtr( SAL_NEWLINE_STRING );
@@ -826,10 +826,10 @@ void OHTMLImportExport::WriteTables()
 
     if(m_xObject.is())
     {
-        sal_Int32* pFormat = new sal_Int32[aNames.getLength()];
+        boost::scoped_array<sal_Int32> pFormat(new sal_Int32[aNames.getLength()]);
 
-        const char **pHorJustify = new const char*[aNames.getLength()];
-        sal_Int32 *pColWidth = new sal_Int32[aNames.getLength()];
+        boost::scoped_array<const char *> pHorJustify(new const char*[aNames.getLength()]);
+        boost::scoped_array<sal_Int32> pColWidth(new sal_Int32[aNames.getLength()]);
 
         sal_Int32 nHeight = 0;
         m_xObject->getPropertyValue(PROPERTY_ROW_HEIGHT) >>= nHeight;
@@ -911,10 +911,6 @@ void OHTMLImportExport::WriteTables()
             ++j;
             TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
         }
-
-        delete [] pFormat;
-        delete [] pHorJustify;
-        delete [] pColWidth;
     }
     else
     {
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 962021e..7c1d5d6 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -43,6 +43,7 @@
 #include <osl/file.hxx>
 #include <rtl/process.h>
 #include "tools/getprocessworkingdir.hxx"
+#include <boost/scoped_array.hpp>
 
 using namespace desktop;
 using namespace ::com::sun::star::uno;
@@ -261,11 +262,11 @@ OUString CreateMD5FromString( const OUString& aMsg )
         const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr();
         sal_uInt32       nSize = ( aMsg.getLength() * sizeof( sal_Unicode ));
         sal_uInt32       nMD5KeyLen = rtl_digest_queryLength( handle );
-        sal_uInt8*       pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ];
+        boost::scoped_array<sal_uInt8> pMD5KeyBuffer(new sal_uInt8[ nMD5KeyLen ]);
 
         rtl_digest_init( handle, pData, nSize );
         rtl_digest_update( handle, pData, nSize );
-        rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen );
+        rtl_digest_get( handle, pMD5KeyBuffer.get(), nMD5KeyLen );
         rtl_digest_destroy( handle );
 
         // Create hex-value string from the MD5 value to keep the string size minimal
@@ -273,7 +274,6 @@ OUString CreateMD5FromString( const OUString& aMsg )
         for ( sal_uInt32 i = 0; i < nMD5KeyLen; i++ )
             aBuffer.append( (sal_Int32)pMD5KeyBuffer[i], 16 );
 
-        delete [] pMD5KeyBuffer;
         return aBuffer.makeStringAndClear();
     }
 
diff --git a/editeng/source/accessibility/AccessibleEditableTextPara.cxx b/editeng/source/accessibility/AccessibleEditableTextPara.cxx
index 6fcf6f8..0c1c867 100644
--- a/editeng/source/accessibility/AccessibleEditableTextPara.cxx
+++ b/editeng/source/accessibility/AccessibleEditableTextPara.cxx
@@ -73,6 +73,7 @@ using namespace std;
 #include "editeng.hrc"
 #include <editeng/eerdll.hxx>
 #include <editeng/numitem.hxx>
+#include <boost/scoped_array.hpp>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::beans;
@@ -1333,7 +1334,7 @@ namespace accessibility
         // build sorted index array
         sal_Int32 nLength = aRes.getLength();
         const beans::PropertyValue* pPairs = aRes.getConstArray();
-        sal_Int32* pIndices = new sal_Int32[nLength];
+        boost::scoped_array<sal_Int32> pIndices(new sal_Int32[nLength]);
         sal_Int32 i = 0;
         for( i = 0; i < nLength; i++ )
             pIndices[i] = i;
@@ -1345,7 +1346,6 @@ namespace accessibility
         {
             pNewValues[i] = pPairs[pIndices[i]];
         }
-        delete[] pIndices;
 
         return aNewValues;
         }


More information about the Libreoffice-commits mailing list