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

Takeshi Abe tabe at fixedpoint.jp
Sat Mar 29 11:41:02 PDT 2014


 editeng/source/editeng/impedit2.cxx  |    7 +++----
 editeng/source/editeng/impedit3.cxx  |   26 +++++++++++++-------------
 editeng/source/outliner/outliner.cxx |    9 ++++-----
 editeng/source/uno/unonrule.cxx      |    6 +++---
 4 files changed, 23 insertions(+), 25 deletions(-)

New commits:
commit 95c45ef7b853bc00ae1734c8271c862dc0665b24
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Sun Mar 30 03:38:11 2014 +0900

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

diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index c0d432e..1852880 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -62,7 +62,7 @@
 #include <sot/formats.hxx>
 
 #include <unicode/ubidi.h>
-
+#include <boost/scoped_array.hpp>
 #include <boost/scoped_ptr.hpp>
 
 #include <algorithm>
@@ -546,7 +546,7 @@ void ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView )
             const EditLine* pLine = pParaPortion->GetLines()[nLine];
             if ( pLine )
             {
-                Rectangle* aRects = new Rectangle[ mpIMEInfos->nLen ];
+                boost::scoped_array<Rectangle> aRects(new Rectangle[ mpIMEInfos->nLen ]);
                 for (sal_Int32 i = 0; i < mpIMEInfos->nLen; ++i)
                 {
                     sal_Int32 nInputPos = mpIMEInfos->aPos.GetIndex() + i;
@@ -555,8 +555,7 @@ void ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView )
                     Rectangle aR2 = GetEditCursor( pParaPortion, nInputPos );
                     aRects[ i ] = pView->GetImpEditView()->GetWindowPos( aR2 );
                 }
-                pView->GetWindow()->SetCompositionCharRect( aRects, mpIMEInfos->nLen );
-                delete[] aRects;
+                pView->GetWindow()->SetCompositionCharRect( aRects.get(), mpIMEInfos->nLen );
             }
         }
     }
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index c095ba2..5c91829 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -72,6 +72,7 @@
 #include <comphelper/processfactory.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <comphelper/string.hxx>
+#include <boost/scoped_array.hpp>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -732,7 +733,7 @@ sal_Bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
     SvxFont aTmpFont( pNode->GetCharAttribs().GetDefFont() );
 
     sal_Bool bCalcCharPositions = sal_True;
-    sal_Int32* pBuf = new sal_Int32[ pNode->Len() ];
+    boost::scoped_array<sal_Int32> pBuf(new sal_Int32[ pNode->Len() ]);
 
     sal_Bool bSameLineAgain = sal_False;    // For TextRanger, if the height changes.
     TabInfo aCurrentTab;
@@ -1056,7 +1057,7 @@ sal_Bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
 
                 if ( bCalcCharPositions || !pPortion->HasValidSize() )
                 {
-                    pPortion->GetSize() = aTmpFont.QuickGetTextSize( GetRefDevice(), pParaPortion->GetNode()->GetString(), nTmpPos, pPortion->GetLen(), pBuf );
+                    pPortion->GetSize() = aTmpFont.QuickGetTextSize( GetRefDevice(), pParaPortion->GetNode()->GetString(), nTmpPos, pPortion->GetLen(), pBuf.get() );
 
                     // #i9050# Do Kerning also behind portions...
                     if ( ( aTmpFont.GetFixKerning() > 0 ) && ( ( nTmpPos + pPortion->GetLen() ) < pNode->Len() ) )
@@ -1071,7 +1072,7 @@ sal_Bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
                     // => Always simply quick inserts.
                     size_t nPos = nTmpPos - pLine->GetStart();
                     EditLine::CharPosArrayType& rArray = pLine->GetCharPosArray();
-                    rArray.insert(rArray.begin()+nPos, pBuf, pBuf+nLen);
+                    rArray.insert(rArray.begin()+nPos, pBuf.get(), pBuf.get()+nLen);
                 }
 
                 // And now check for Compression:
@@ -1560,7 +1561,7 @@ sal_Bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
     if ( bLineBreak )
         CreateAndInsertEmptyLine( pParaPortion, nStartPosY );
 
-    delete[] pBuf;
+    pBuf.reset();
 
     sal_Bool bHeightChanged = FinishCreateLines( pParaPortion );
 
@@ -3029,7 +3030,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRect, Point aSt
                                 sal_Int32 nTextStart = 0;
                                 sal_Int32 nTextLen = 0;
                                 const sal_Int32* pDXArray = 0;
-                                sal_Int32* pTmpDXArray = 0;
+                                boost::scoped_array<sal_Int32> pTmpDXArray;
 
                                 if ( pTextPortion->GetKind() == PORTIONKIND_TEXT )
                                 {
@@ -3173,11 +3174,11 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRect, Point aSt
                                         }
                                     }
 
-                                    pTmpDXArray = new sal_Int32[ aText.getLength() ];
-                                    pDXArray = pTmpDXArray;
+                                    pTmpDXArray.reset(new sal_Int32[ aText.getLength() ]);
+                                    pDXArray = pTmpDXArray.get();
                                     Font _aOldFont( GetRefDevice()->GetFont() );
                                     aTmpFont.SetPhysFont( GetRefDevice() );
-                                    aTmpFont.QuickGetTextSize( GetRefDevice(), aText, nTextStart, nTextLen, pTmpDXArray );
+                                    aTmpFont.QuickGetTextSize( GetRefDevice(), aText, nTextStart, nTextLen, pTmpDXArray.get() );
                                     if ( aStatus.DoRestoreFont() )
                                         GetRefDevice()->SetFont( _aOldFont );
 
@@ -3203,11 +3204,11 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRect, Point aSt
                                     nTextLen = aText.getLength();
 
                                     // crash when accessing 0 pointer in pDXArray
-                                    pTmpDXArray = new sal_Int32[ aText.getLength() ];
-                                    pDXArray = pTmpDXArray;
+                                    pTmpDXArray.reset(new sal_Int32[ aText.getLength() ]);
+                                    pDXArray = pTmpDXArray.get();
                                     Font _aOldFont( GetRefDevice()->GetFont() );
                                     aTmpFont.SetPhysFont( GetRefDevice() );
-                                    aTmpFont.QuickGetTextSize( GetRefDevice(), aText, 0, aText.getLength(), pTmpDXArray );
+                                    aTmpFont.QuickGetTextSize( GetRefDevice(), aText, 0, aText.getLength(), pTmpDXArray.get() );
                                     if ( aStatus.DoRestoreFont() )
                                         GetRefDevice()->SetFont( _aOldFont );
                                 }
@@ -3473,8 +3474,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRect, Point aSt
 
                                 pOutDev->Pop();
 
-                                //The C++ language guarantees that delete p will do nothing if p is equal to NULL.
-                                delete[] pTmpDXArray;
+                                pTmpDXArray.reset();
 
                                 if ( pTextPortion->GetKind() == PORTIONKIND_FIELD )
                                 {
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx
index 5726854..e019d91 100644
--- a/editeng/source/outliner/outliner.cxx
+++ b/editeng/source/outliner/outliner.cxx
@@ -54,6 +54,7 @@
 // calculate if it's RTL or not
 #include <unicode/ubidi.h>
 #include <cassert>
+#include <boost/scoped_array.hpp>
 using ::std::advance;
 
 
@@ -1007,8 +1008,8 @@ void Outliner::PaintBullet( sal_Int32 nPara, const Point& rStartPos,
                 if(bStrippingPortions)
                 {
                     const Font aSvxFont(pOutDev->GetFont());
-                    sal_Int32* pBuf = new sal_Int32[ pPara->GetText().getLength() ];
-                    pOutDev->GetTextArray( pPara->GetText(), pBuf );
+                    boost::scoped_array<sal_Int32> pBuf(new sal_Int32[ pPara->GetText().getLength() ]);
+                    pOutDev->GetTextArray( pPara->GetText(), pBuf.get() );
 
                     if(bSymbol)
                     {
@@ -1017,10 +1018,8 @@ void Outliner::PaintBullet( sal_Int32 nPara, const Point& rStartPos,
                         aTextPos.Y() -= aMetric.GetDescent();
                     }
 
-                    DrawingText(aTextPos, pPara->GetText(), 0, pPara->GetText().getLength(), pBuf,
+                    DrawingText(aTextPos, pPara->GetText(), 0, pPara->GetText().getLength(), pBuf.get(),
                         aSvxFont, nPara, -1, bRightToLeftPara, 0, 0, false, false, true, 0, Color(), Color());
-
-                    delete[] pBuf;
                 }
                 else
                 {
diff --git a/editeng/source/uno/unonrule.cxx b/editeng/source/uno/unonrule.cxx
index 2898d91..3b3f242 100644
--- a/editeng/source/uno/unonrule.cxx
+++ b/editeng/source/uno/unonrule.cxx
@@ -35,6 +35,7 @@
 #include <editeng/unonrule.hxx>
 #include <editeng/editids.hrc>
 #include <editeng/numdef.hxx>
+#include <boost/scoped_array.hpp>
 
 using ::com::sun::star::util::XCloneable;
 using ::com::sun::star::ucb::XAnyCompare;
@@ -176,7 +177,7 @@ Sequence<beans::PropertyValue> SvxUnoNumberingRules::getNumberingRuleByIndex( sa
     sal_uInt16 nIdx = 0;
 
     const int nProps = 15;
-    beans::PropertyValue* pArray = new beans::PropertyValue[nProps];
+    boost::scoped_array<beans::PropertyValue> pArray(new beans::PropertyValue[nProps]);
 
     Any aVal;
     {
@@ -261,9 +262,8 @@ Sequence<beans::PropertyValue> SvxUnoNumberingRules::getNumberingRuleByIndex( sa
     pArray[nIdx++] = beans::PropertyValue(OUString(UNO_NAME_NRULE_BULLET_RELSIZE), -1, aVal, beans::PropertyState_DIRECT_VALUE);
 
     DBG_ASSERT( nIdx <= nProps, "FixMe: overflow in Array!!! [CL]" );
-    Sequence< beans::PropertyValue> aSeq(pArray, nIdx);
+    Sequence< beans::PropertyValue> aSeq(pArray.get(), nIdx);
 
-    delete [] pArray;
     return aSeq;
 }
 


More information about the Libreoffice-commits mailing list