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

Takeshi Abe tabe at fixedpoint.jp
Mon May 5 10:26:59 PDT 2014


 sc/source/ui/unoobj/appluno.cxx  |    7 ++---
 sc/source/ui/unoobj/cellsuno.cxx |   50 ++++++++++++++-------------------------
 sc/source/ui/unoobj/datauno.cxx  |    6 ++--
 sc/source/ui/view/formatsh.cxx   |   28 ++++++++-------------
 4 files changed, 36 insertions(+), 55 deletions(-)

New commits:
commit 6726fb5ce2daa363b7e885ae45e59feeb733f051
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Tue May 6 02:23:48 2014 +0900

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

diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx
index 2878fed..5ba0f78 100644
--- a/sc/source/ui/unoobj/appluno.cxx
+++ b/sc/source/ui/unoobj/appluno.cxx
@@ -39,6 +39,7 @@
 #include "funcdesc.hxx"
 #include <com/sun/star/sheet/FunctionArgument.hpp>
 #include "ScPanelFactory.hxx"
+#include <boost/scoped_array.hpp>
 
 using namespace com::sun::star;
 
@@ -634,18 +635,16 @@ void SAL_CALL ScRecentFunctionsObj::setRecentFunctionIds(
     sal_uInt16 nCount = (sal_uInt16) std::min( aRecentFunctionIds.getLength(), (sal_Int32) LRU_MAX );
     const sal_Int32* pAry = aRecentFunctionIds.getConstArray();
 
-    sal_uInt16* pFuncs = nCount ? new sal_uInt16[nCount] : NULL;
+    boost::scoped_array<sal_uInt16> pFuncs(nCount ? new sal_uInt16[nCount] : NULL);
     for (sal_uInt16 i=0; i<nCount; i++)
         pFuncs[i] = (sal_uInt16)pAry[i];        //! auf gueltige Werte testen?
 
     ScModule* pScMod = SC_MOD();
     ScAppOptions aNewOpts(pScMod->GetAppOptions());
-    aNewOpts.SetLRUFuncList(pFuncs, nCount);
+    aNewOpts.SetLRUFuncList(pFuncs.get(), nCount);
     pScMod->SetAppOptions(aNewOpts);
 
     pScMod->RecentFunctionsChanged();       // update function list child window
-
-    delete[] pFuncs;
 }
 
 sal_Int32 SAL_CALL ScRecentFunctionsObj::getMaxRecentFunctions() throw(uno::RuntimeException, std::exception)
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 9a13025..e7d3abd 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -127,6 +127,7 @@
 #include "dputil.hxx"
 
 #include <list>
+#include <boost/scoped_array.hpp>
 #include <boost/scoped_ptr.hpp>
 
 using namespace com::sun::star;
@@ -1536,9 +1537,9 @@ void ScCellRangesBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
         const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
 
         ScDocument* pDoc = pDocShell->GetDocument();
-        ScRangeList* pUndoRanges = NULL;
+        boost::scoped_ptr<ScRangeList> pUndoRanges;
         if ( pDoc->HasUnoRefUndo() )
-            pUndoRanges = new ScRangeList( aRanges );
+            pUndoRanges.reset(new ScRangeList( aRanges ));
 
         if ( aRanges.UpdateReference( rRef.GetMode(), pDoc, rRef.GetRange(),
                                     rRef.GetDx(), rRef.GetDy(), rRef.GetDz() ) )
@@ -1570,8 +1571,6 @@ void ScCellRangesBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
             if ( pUndoRanges )
                 pDoc->AddUnoRefChange( nObjectId, *pUndoRanges );
         }
-
-        delete pUndoRanges;
     }
     else if ( rHint.ISA( SfxSimpleHint ) )
     {
@@ -2403,10 +2402,10 @@ void ScCellRangesBase::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pE
                                        formula::FormulaGrammar::GRAM_UNSPECIFIED :
                                        formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
 
-                                ScValidationData* pNewData =
-                                        pValidObj->CreateValidationData( pDoc, eGrammar );
+                                boost::scoped_ptr<ScValidationData> pNewData(
+                                        pValidObj->CreateValidationData( pDoc, eGrammar ));
                                 sal_uLong nIndex = pDoc->AddValidationEntry( *pNewData );
-                                delete pNewData;
+                                pNewData.reset();
 
                                 ScPatternAttr aPattern( pDoc->GetPool() );
                                 aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
@@ -2643,7 +2642,7 @@ void SAL_CALL ScCellRangesBase::setPropertyValues( const uno::Sequence< OUString
         const OUString* pNames = aPropertyNames.getConstArray();
         const uno::Any* pValues = aValues.getConstArray();
 
-        const SfxItemPropertySimpleEntry** pEntryArray = new const SfxItemPropertySimpleEntry*[nCount];
+        boost::scoped_array<const SfxItemPropertySimpleEntry*> pEntryArray(new const SfxItemPropertySimpleEntry*[nCount]);
 
         sal_Int32 i;
         for(i = 0; i < nCount; i++)
@@ -2670,8 +2669,8 @@ void SAL_CALL ScCellRangesBase::setPropertyValues( const uno::Sequence< OUString
         }
 
         ScDocument* pDoc = pDocShell->GetDocument();
-        ScPatternAttr* pOldPattern = NULL;
-        ScPatternAttr* pNewPattern = NULL;
+        boost::scoped_ptr<ScPatternAttr> pOldPattern;
+        boost::scoped_ptr<ScPatternAttr> pNewPattern;
 
         for(i = 0; i < nCount; i++)
         {
@@ -2684,9 +2683,9 @@ void SAL_CALL ScCellRangesBase::setPropertyValues( const uno::Sequence< OUString
                 {
                     if ( !pOldPattern )
                     {
-                        pOldPattern = new ScPatternAttr( *GetCurrentAttrsDeep() );
+                        pOldPattern.reset(new ScPatternAttr( *GetCurrentAttrsDeep() ));
                         pOldPattern->GetItemSet().ClearInvalidItems();
-                        pNewPattern = new ScPatternAttr( pDoc->GetPool() );
+                        pNewPattern.reset(new ScPatternAttr( pDoc->GetPool() ));
                     }
 
                     //  collect items in pNewPattern, apply with one call after the loop
@@ -2710,10 +2709,6 @@ void SAL_CALL ScCellRangesBase::setPropertyValues( const uno::Sequence< OUString
 
         if ( pNewPattern && !aRanges.empty() )
             pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), *pNewPattern, true, true );
-
-        delete pNewPattern;
-        delete pOldPattern;
-        delete[] pEntryArray;
     }
 }
 
@@ -2790,7 +2785,7 @@ uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::set
         const OUString* pNames = aPropertyNames.getConstArray();
         const uno::Any* pValues = aValues.getConstArray();
 
-        const SfxItemPropertySimpleEntry** pMapArray = new const SfxItemPropertySimpleEntry*[nCount];
+        boost::scoped_array<const SfxItemPropertySimpleEntry*> pMapArray(new const SfxItemPropertySimpleEntry*[nCount]);
 
         sal_Int32 i;
         for(i = 0; i < nCount; i++)
@@ -2817,8 +2812,8 @@ uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::set
         }
 
         ScDocument* pDoc = pDocShell->GetDocument();
-        ScPatternAttr* pOldPattern = NULL;
-        ScPatternAttr* pNewPattern = NULL;
+        boost::scoped_ptr<ScPatternAttr> pOldPattern;
+        boost::scoped_ptr<ScPatternAttr> pNewPattern;
 
         sal_Int32 nFailed(0);
         for(i = 0; i < nCount; i++)
@@ -2832,9 +2827,9 @@ uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::set
                 {
                     if ( !pOldPattern )
                     {
-                        pOldPattern = new ScPatternAttr( *GetCurrentAttrsDeep() );
+                        pOldPattern.reset(new ScPatternAttr( *GetCurrentAttrsDeep() ));
                         pOldPattern->GetItemSet().ClearInvalidItems();
-                        pNewPattern = new ScPatternAttr( pDoc->GetPool() );
+                        pNewPattern.reset(new ScPatternAttr( pDoc->GetPool() ));
                     }
 
                     //  collect items in pNewPattern, apply with one call after the loop
@@ -2883,10 +2878,6 @@ uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::set
         if ( pNewPattern && !aRanges.empty() )
             pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), *pNewPattern, true, true );
 
-        delete pNewPattern;
-        delete pOldPattern;
-        delete[] pMapArray;
-
         aReturns.realloc(nFailed);
 
         return aReturns;
@@ -3043,7 +3034,7 @@ uno::Sequence< uno::Sequence<double> > SAL_CALL ScCellRangesBase::getData()
     throw(uno::RuntimeException, std::exception)
 {
     SolarMutexGuard aGuard;
-    ScMemChart* pMemChart = CreateMemChart_Impl();
+    boost::scoped_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
     if ( pMemChart )
     {
         sal_Int32 nColCount = pMemChart->GetColCount();
@@ -3061,7 +3052,6 @@ uno::Sequence< uno::Sequence<double> > SAL_CALL ScCellRangesBase::getData()
             pRowAry[nRow] = aColSeq;
         }
 
-        delete pMemChart;
         return aRowSeq;
     }
 
@@ -3158,7 +3148,7 @@ uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getRowDescriptions()
     throw(uno::RuntimeException, std::exception)
 {
     SolarMutexGuard aGuard;
-    ScMemChart* pMemChart = CreateMemChart_Impl();
+    boost::scoped_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
     if ( pMemChart )
     {
         sal_Int32 nRowCount = static_cast<sal_Int32>(pMemChart->GetRowCount());
@@ -3167,7 +3157,6 @@ uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getRowDescriptions()
         for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
             pAry[nRow] = pMemChart->GetRowText(static_cast<short>(nRow));
 
-        delete pMemChart;
         return aSeq;
     }
     return uno::Sequence<OUString>(0);
@@ -3230,7 +3219,7 @@ uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getColumnDescriptions()
     throw(uno::RuntimeException, std::exception)
 {
     SolarMutexGuard aGuard;
-    ScMemChart* pMemChart = CreateMemChart_Impl();
+    boost::scoped_ptr<ScMemChart> pMemChart(CreateMemChart_Impl());
     if ( pMemChart )
     {
         sal_Int32 nColCount = pMemChart->GetColCount();
@@ -3239,7 +3228,6 @@ uno::Sequence<OUString> SAL_CALL ScCellRangesBase::getColumnDescriptions()
         for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
             pAry[nCol] = pMemChart->GetColText(static_cast<short>(nCol));
 
-        delete pMemChart;
         return aSeq;
     }
     return uno::Sequence<OUString>(0);
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index 8fefadc..9eb5ebd 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -58,6 +58,7 @@
 #include <svx/dataaccessdescriptor.hxx>
 
 #include <limits>
+#include <boost/scoped_array.hpp>
 
 using namespace com::sun::star;
 
@@ -912,18 +913,17 @@ void SAL_CALL ScConsolidationDescriptor::setSources(
     if (nCount)
     {
         const table::CellRangeAddress* pAry = aSources.getConstArray();
-        ScArea** pNew = new ScArea*[nCount];
+        boost::scoped_array<ScArea*> pNew(new ScArea*[nCount]);
         sal_uInt16 i;
         for (i=0; i<nCount; i++)
             pNew[i] = new ScArea( pAry[i].Sheet,
                     static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow,
                     static_cast<SCCOL>(pAry[i].EndColumn),   pAry[i].EndRow );
 
-        aParam.SetAreas( pNew, nCount );    // kopiert alles
+        aParam.SetAreas( pNew.get(), nCount );    // kopiert alles
 
         for (i=0; i<nCount; i++)
             delete pNew[i];
-        delete[] pNew;
     }
     else
         aParam.ClearDataAreas();
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 429bc21..3522087 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -772,7 +772,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
             if ( pStyleSheet )
             {
                 SfxStyleFamily  eFam    = pStyleSheet->GetFamily();
-                SfxAbstractTabDialog* pDlg    = NULL;
+                boost::scoped_ptr<SfxAbstractTabDialog> pDlg;
                 sal_uInt16          nRsc    = 0;
 
                 // alte Items aus der Vorlage merken
@@ -858,7 +858,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                pDlg = pFact->CreateScStyleDlg( pParent, *pStyleSheet, nRsc, nRsc );
+                pDlg.reset(pFact->CreateScStyleDlg( pParent, *pStyleSheet, nRsc, nRsc ));
                 OSL_ENSURE(pDlg, "Dialog create fail!");
                 short nResult = pDlg->Execute();
                 pTabViewShell->SetInFormatDialog(false);
@@ -946,7 +946,6 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
                         pDocSh->PostPaintGridAll();
                     }
                 }
-                delete pDlg;
             }
         }
 
@@ -1775,16 +1774,16 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
                 {
                     ::editeng::SvxBorderLine*          pDefLine = pTabViewShell->GetDefaultFrameLine();
                     const ScPatternAttr*    pOldAttrs = pTabViewShell->GetSelectionPattern();
-                    SfxItemSet*             pOldSet =
+                    boost::scoped_ptr<SfxItemSet> pOldSet(
                                                 new SfxItemSet(
                                                         *(pDoc->GetPool()),
                                                         ATTR_PATTERN_START,
-                                                        ATTR_PATTERN_END );
-                    SfxItemSet*             pNewSet =
+                                                        ATTR_PATTERN_END ));
+                    boost::scoped_ptr<SfxItemSet> pNewSet(
                                                 new SfxItemSet(
                                                         *(pDoc->GetPool()),
                                                         ATTR_PATTERN_START,
-                                                        ATTR_PATTERN_END );
+                                                        ATTR_PATTERN_END ));
                     const SfxPoolItem&      rBorderAttr =
                                                 pOldAttrs->GetItemSet().
                                                     Get( ATTR_BORDER );
@@ -1833,10 +1832,7 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
                     }
 
                     pOldSet->Put( rBorderAttr );
-                    pTabViewShell->ApplyAttributes( pNewSet, pOldSet );
-
-                    delete pOldSet;
-                    delete pNewSet;
+                    pTabViewShell->ApplyAttributes( pNewSet.get(), pOldSet.get() );
                 }
                 break;
 
@@ -1844,8 +1840,8 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
             case SID_ATTR_BORDER_DIAG_BLTR:
                 {
                     const ScPatternAttr* pOldAttrs = pTabViewShell->GetSelectionPattern();
-                    SfxItemSet* pOldSet = new SfxItemSet(pOldAttrs->GetItemSet());
-                    SfxItemSet* pNewSet = new SfxItemSet(pOldAttrs->GetItemSet());
+                    boost::scoped_ptr<SfxItemSet> pOldSet(new SfxItemSet(pOldAttrs->GetItemSet()));
+                    boost::scoped_ptr<SfxItemSet> pNewSet(new SfxItemSet(pOldAttrs->GetItemSet()));
                     const SfxPoolItem* pItem = 0;
 
                     if(SID_ATTR_BORDER_DIAG_TLBR == nSlot)
@@ -1856,7 +1852,7 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
                             aItem.SetLine(((const SvxLineItem&)pNewAttrs->Get(ATTR_BORDER_TLBR)).GetLine());
                             pNewSet->Put(aItem);
                             rReq.AppendItem(aItem);
-                            pTabViewShell->ApplyAttributes(pNewSet, pOldSet);
+                            pTabViewShell->ApplyAttributes(pNewSet.get(), pOldSet.get());
                         }
                     }
                     else // if( nSlot == SID_ATTR_BORDER_DIAG_BLTR )
@@ -1867,12 +1863,10 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
                             aItem.SetLine(((const SvxLineItem&)pNewAttrs->Get(ATTR_BORDER_BLTR)).GetLine());
                             pNewSet->Put(aItem);
                             rReq.AppendItem(aItem);
-                            pTabViewShell->ApplyAttributes(pNewSet, pOldSet);
+                            pTabViewShell->ApplyAttributes(pNewSet.get(), pOldSet.get());
                         }
                     }
 
-                    delete pOldSet;
-                    delete pNewSet;
                     rBindings.Invalidate(nSlot);
                 }
                 break;


More information about the Libreoffice-commits mailing list