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

Takeshi Abe tabe at fixedpoint.jp
Mon May 12 02:49:08 PDT 2014


 sc/source/ui/view/cellsh2.cxx |   21 +++++++------------
 sc/source/ui/view/cellsh3.cxx |   45 ++++++++++++++++++------------------------
 sc/source/ui/view/dbfunc3.cxx |   12 +++++------
 sc/source/ui/view/editsh.cxx  |   16 ++++----------
 4 files changed, 39 insertions(+), 55 deletions(-)

New commits:
commit 22259f02b211694525251afcdba12a5d3a43cbae
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Mon May 12 18:46:49 2014 +0900

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

diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 097fa19..52ad408 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -64,6 +64,8 @@
 
 #include <config_orcus.h>
 
+#include <boost/scoped_ptr.hpp>
+
 using namespace com::sun::star;
 
 static bool lcl_GetTextToColumnsRange( const ScViewData* pData, ScRange& rRange )
@@ -158,7 +160,7 @@ static bool lcl_GetSortParam( const ScViewData* pData, ScSortParam& rSortParam )
         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
         OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-        AbstractScSortWarningDlg* pWarningDlg = pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(), aExtendStr, aCurrentStr );
+        boost::scoped_ptr<AbstractScSortWarningDlg> pWarningDlg(pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(), aExtendStr, aCurrentStr ));
         OSL_ENSURE(pWarningDlg, "Dialog create fail!");
         short bResult = pWarningDlg->Execute();
         if( bResult == BTN_EXTEND_RANGE || bResult == BTN_CURRENT_SELECTION )
@@ -175,7 +177,6 @@ static bool lcl_GetSortParam( const ScViewData* pData, ScSortParam& rSortParam )
             pData->GetDocShell()->CancelAutoDBRange();
         }
 
-        delete pWarningDlg;
         pTabViewShell->ClearHighlightRanges();
     }
     return bSort;
@@ -467,7 +468,6 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
 
                     if( lcl_GetSortParam( pData, aSortParam ) )
                     {
-                        SfxAbstractTabDialog* pDlg = NULL;
                         ScDocument* pDoc = GetViewData()->GetDocument();
                         SfxItemSet  aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA );
 
@@ -481,7 +481,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                         assert(pFact); //ScAbstractFactory create fail!
 
-                        pDlg = pFact->CreateScSortDlg(pTabViewShell->GetDialogParent(),  &aArgSet);
+                        boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScSortDlg(pTabViewShell->GetDialogParent(),  &aArgSet));
                         assert(pDlg); //Dialog create fail!
                         pDlg->SetCurPageId("criteria");  // 1=sort field tab  2=sort options tab
 
@@ -536,8 +536,6 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                         }
                         else
                             GetViewData()->GetDocShell()->CancelAutoDBRange();
-
-                        delete pDlg;
                     }
                 }
             }
@@ -724,8 +722,8 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                        AbstractScSelEntryDlg* pDlg = pFact->CreateScSelEntryDlg( pTabViewShell->GetDialogParent(),
-                                                                                aList );
+                        boost::scoped_ptr<AbstractScSelEntryDlg> pDlg(pFact->CreateScSelEntryDlg( pTabViewShell->GetDialogParent(),
+                                                                                                  aList ));
                         OSL_ENSURE(pDlg, "Dialog create fail!");
                         if ( pDlg->Execute() == RET_OK )
                         {
@@ -734,8 +732,6 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                             rReq.AppendItem( SfxStringItem( SID_SELECT_DB, aName ) );
                             rReq.Done();
                         }
-
-                        delete pDlg;
                     }
                 }
             }
@@ -964,8 +960,8 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
 
                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                     OSL_ENSURE( pFact, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" );
-                    AbstractScImportAsciiDlg *pDlg = pFact->CreateScImportAsciiDlg(
-                        NULL, OUString(), &aStream, SC_TEXTTOCOLUMNS);
+                    boost::scoped_ptr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg(
+                        NULL, OUString(), &aStream, SC_TEXTTOCOLUMNS));
                     OSL_ENSURE( pDlg, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" );
 
                     if ( pDlg->Execute() == RET_OK )
@@ -987,7 +983,6 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
 
                         pDocSh->GetUndoManager()->LeaveListAction();
                     }
-                    delete pDlg;
                 }
             }
             break;
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 69c6d29..3ab047f 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -48,6 +48,8 @@
 #include "sccollaboration.hxx"
 #endif
 
+#include <boost/scoped_ptr.hpp>
+
 #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
 
 using sc::HMMToTwips;
@@ -323,15 +325,15 @@ void ScCellShell::Execute( SfxRequest& rReq )
 
                     // set cell attribute without dialog:
 
-                    SfxItemSet*     pEmptySet =
+                    boost::scoped_ptr<SfxItemSet> pEmptySet(
                                         new SfxItemSet( *pReqArgs->GetPool(),
                                                         ATTR_PATTERN_START,
-                                                        ATTR_PATTERN_END );
+                                                        ATTR_PATTERN_END ));
 
-                    SfxItemSet*     pNewSet =
+                    boost::scoped_ptr<SfxItemSet> pNewSet(
                                         new SfxItemSet( *pReqArgs->GetPool(),
                                                         ATTR_PATTERN_START,
-                                                        ATTR_PATTERN_END );
+                                                        ATTR_PATTERN_END ));
 
                     const SfxPoolItem*  pAttr = NULL;
                     sal_uInt16              nWhich = 0;
@@ -340,10 +342,10 @@ void ScCellShell::Execute( SfxRequest& rReq )
                         if ( pReqArgs->GetItemState( nWhich, true, &pAttr ) == SFX_ITEM_SET )
                             pNewSet->Put( *pAttr );
 
-                    pTabViewShell->ApplyAttributes( pNewSet, pEmptySet );
+                    pTabViewShell->ApplyAttributes( pNewSet.get(), pEmptySet.get() );
 
-                    delete pNewSet;
-                    delete pEmptySet;
+                    pNewSet.reset();
+                    pEmptySet.reset();
 
                     rReq.Done();
                 }
@@ -491,7 +493,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                             ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                             OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                            AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg(pTabViewShell->GetDialogParent(), aName, false, bSheetProtected);
+                            boost::scoped_ptr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(pTabViewShell->GetDialogParent(), aName, false, bSheetProtected));
                             OSL_ENSURE(pNewDlg, "Dialog create fail!");
                             if ( pNewDlg->Execute() == RET_OK )
                             {
@@ -502,7 +504,6 @@ void ScCellShell::Execute( SfxRequest& rReq )
                                 rReq.AppendItem( SfxStringItem( SID_NEW_TABLENAME, aComment ) );
                                 rReq.Done();
                             }
-                            delete pNewDlg;
                         }
                     }
                     else if( ! rReq.IsAPI() )
@@ -543,10 +544,10 @@ void ScCellShell::Execute( SfxRequest& rReq )
                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                     assert(pFact); //ScAbstractFactory create fail!
 
-                    AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg(
+                    boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
                         pTabViewShell->GetDialogParent(), "RowHeightDialog",
                         nCurHeight, ScGlobal::nStdRowHeight,
-                        eMetric, 2, MAX_ROW_HEIGHT);
+                        eMetric, 2, MAX_ROW_HEIGHT));
                     assert(pDlg); //Dialog create fail
 
                     if ( pDlg->Execute() == RET_OK )
@@ -559,7 +560,6 @@ void ScCellShell::Execute( SfxRequest& rReq )
                         rReq.Done();
 
                     }
-                    delete pDlg;
                 }
             }
             break;
@@ -585,9 +585,9 @@ void ScCellShell::Execute( SfxRequest& rReq )
                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                     assert(pFact); //ScAbstractFactory create fail!
 
-                    AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg(
+                    boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
                         pTabViewShell->GetDialogParent(), "OptimalRowHeightDialog",
-                        ScGlobal::nLastRowHeightExtra, 0, eMetric, 1, MAX_EXTRA_HEIGHT);
+                        ScGlobal::nLastRowHeightExtra, 0, eMetric, 1, MAX_EXTRA_HEIGHT));
                     assert(pDlg); //Dialog create fail!
 
                     if ( pDlg->Execute() == RET_OK )
@@ -601,7 +601,6 @@ void ScCellShell::Execute( SfxRequest& rReq )
                         rReq.Done();
 
                     }
-                    delete pDlg;
                 }
             }
             break;
@@ -628,9 +627,9 @@ void ScCellShell::Execute( SfxRequest& rReq )
                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                     assert(pFact); //ScAbstractFactory create fail!
 
-                    AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg(
+                    boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
                         pTabViewShell->GetDialogParent(), "ColWidthDialog", nCurHeight,
-                        STD_COL_WIDTH, eMetric, 2, MAX_COL_WIDTH);
+                        STD_COL_WIDTH, eMetric, 2, MAX_COL_WIDTH));
                     assert(pDlg); //Dialog create fail!
 
                     if ( pDlg->Execute() == RET_OK )
@@ -643,7 +642,6 @@ void ScCellShell::Execute( SfxRequest& rReq )
                         rReq.Done();
 
                     }
-                    delete pDlg;
                 }
             }
             break;
@@ -669,9 +667,9 @@ void ScCellShell::Execute( SfxRequest& rReq )
                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                     assert(pFact); //ScAbstractFactory create fail!
 
-                    AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg(
+                    boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
                         pTabViewShell->GetDialogParent(), "OptimalColWidthDialog",
-                        ScGlobal::nLastColWidthExtra, STD_EXTRA_WIDTH, eMetric, 1, MAX_EXTRA_WIDTH);
+                        ScGlobal::nLastColWidthExtra, STD_EXTRA_WIDTH, eMetric, 1, MAX_EXTRA_WIDTH));
                     assert(pDlg); //Dialog create fail!
                     if ( pDlg->Execute() == RET_OK )
                     {
@@ -683,7 +681,6 @@ void ScCellShell::Execute( SfxRequest& rReq )
                         rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
                         rReq.Done();
                     }
-                    delete pDlg;
                 }
             }
             break;
@@ -818,11 +815,11 @@ void ScCellShell::Execute( SfxRequest& rReq )
                     else
                     {
                         ScGlobal::ClearAutoFormat();
-                        ScAutoFormatData* pNewEntry = pTabViewShell->CreateAutoFormatData();
+                        boost::scoped_ptr<ScAutoFormatData> pNewEntry(pTabViewShell->CreateAutoFormatData());
                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                        AbstractScAutoFormatDlg* pDlg = pFact->CreateScAutoFormatDlg(pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry, GetViewData());
+                        boost::scoped_ptr<AbstractScAutoFormatDlg> pDlg(pFact->CreateScAutoFormatDlg(pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry.get(), GetViewData()));
                         OSL_ENSURE(pDlg, "Dialog create fail!");
 
                         if ( pDlg->Execute() == RET_OK )
@@ -840,8 +837,6 @@ void ScCellShell::Execute( SfxRequest& rReq )
                                 rReq.Done();
                             }
                         }
-                        delete pDlg;
-                        delete pNewEntry;
                     }
                 }
                 else
diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index b975edf..76d6cc2 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -1846,10 +1846,10 @@ bool ScDBFunc::DataPilotMove( const ScRange& rSource, const ScAddress& rDest )
 
                 // apply changes
                 ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
-                ScDPObject* pNewObj = new ScDPObject( *pDPObj );
+                boost::scoped_ptr<ScDPObject> pNewObj(new ScDPObject( *pDPObj ));
                 pNewObj->SetSaveData( aData );
-                aFunc.DataPilotUpdate( pDPObj, pNewObj, true, false );      //! bApi for drag&drop?
-                delete pNewObj;
+                aFunc.DataPilotUpdate( pDPObj, pNewObj.get(), true, false );      //! bApi for drag&drop?
+                pNewObj.reset();
 
                 Unmark();       // entry was moved - no use in leaving the old cell selected
 
@@ -1975,10 +1975,10 @@ void ScDBFunc::SetDataPilotDetails(bool bShow, const OUString* pNewDimensionName
 
                 // apply changes
                 ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
-                ScDPObject* pNewObj = new ScDPObject( *pDPObj );
+                boost::scoped_ptr<ScDPObject> pNewObj(new ScDPObject( *pDPObj ));
                 pNewObj->SetSaveData( aData );
-                aFunc.DataPilotUpdate( pDPObj, pNewObj, true, false );
-                delete pNewObj;
+                aFunc.DataPilotUpdate( pDPObj, pNewObj.get(), true, false );
+                pNewObj.reset();
 
                 // unmark cell selection
                 Unmark();
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index 542e6ca..5a26a6e 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -75,6 +75,7 @@
 
 #include "scui_def.hxx"
 #include "scabstdlg.hxx"
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
 
@@ -413,17 +414,14 @@ void ScEditShell::Execute( SfxRequest& rReq )
                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                AbstractScNamePasteDlg* pDlg = pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pViewData->GetDocShell(), false );
+                boost::scoped_ptr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pViewData->GetDocShell(), false ));
                 OSL_ENSURE(pDlg, "Dialog create fail!");
                 short nRet = pDlg->Execute();
                 // pDlg is needed below
 
                 // while the dialog was open, edit mode may have been stopped
                 if (!SC_MOD()->IsInputMode())
-                {
-                    delete pDlg;
                     return;
-                }
 
                 if ( nRet == BTN_PASTE_NAME )
                 {
@@ -441,7 +439,7 @@ void ScEditShell::Execute( SfxRequest& rReq )
                             pTopView->InsertText(aBuffer.makeStringAndClear());
                     }
                 }
-                delete pDlg;
+                pDlg.reset();
 
                 if (pTopView)
                     pTopView->GetWindow()->GrabFocus();
@@ -458,8 +456,8 @@ void ScEditShell::Execute( SfxRequest& rReq )
                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                SfxAbstractTabDialog* pDlg = pFact->CreateScCharDlg(
-                    pViewData->GetDialogParent(), &aAttrs, pObjSh);
+                boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
+                    pViewData->GetDialogParent(), &aAttrs, pObjSh));
                 OSL_ENSURE(pDlg, "Dialog create fail!");
                 if (nSlot == SID_CHAR_DLG_EFFECT)
                 {
@@ -470,17 +468,13 @@ void ScEditShell::Execute( SfxRequest& rReq )
 
                 // while the dialog was open, edit mode may have been stopped
                 if (!SC_MOD()->IsInputMode())
-                {
-                    delete pDlg;
                     return;
-                }
 
                 if ( nRet == RET_OK )
                 {
                     const SfxItemSet* pOut = pDlg->GetOutputItemSet();
                     pTableView->SetAttribs( *pOut );
                 }
-                delete pDlg;
             }
             break;
 


More information about the Libreoffice-commits mailing list