diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-01-24 10:36:12 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-01-24 10:43:43 +0900 |
commit | 530ddca40fc939a4d6ba6db503f0e49c10af4298 (patch) | |
tree | b6f50a86ce5dfd0afd869f2a841a7beeb65662e1 | |
parent | 2d041ee46f68caf9760575d971127c27e279d2ef (diff) |
Avoid resource leaks in case of exception
Change-Id: I25d012b400ce0f467e6dfa03517bfebd9c945a66
-rw-r--r-- | sw/source/ui/app/applab.cxx | 9 | ||||
-rw-r--r-- | sw/source/ui/app/docsh2.cxx | 12 | ||||
-rw-r--r-- | sw/source/ui/dochdl/swdtflvr.cxx | 10 |
3 files changed, 14 insertions, 17 deletions
diff --git a/sw/source/ui/app/applab.cxx b/sw/source/ui/app/applab.cxx index 735a9083094f..829e3df9c305 100644 --- a/sw/source/ui/app/applab.cxx +++ b/sw/source/ui/app/applab.cxx @@ -159,7 +159,7 @@ void SwModule::InsertLab(SfxRequest& rReq, sal_Bool bLabel) static sal_uInt16 nBCTitleNo = 0; // Create DB-Manager - SwNewDBMgr* pNewDBMgr = new SwNewDBMgr; + boost::scoped_ptr<SwNewDBMgr> pNewDBMgr(new SwNewDBMgr); // Read SwLabItem from Config SwLabCfgItem aLabCfg(bLabel); @@ -171,7 +171,7 @@ void SwModule::InsertLab(SfxRequest& rReq, sal_Bool bLabel) SwAbstractDialogFactory* pDialogFactory = SwAbstractDialogFactory::Create(); OSL_ENSURE(pDialogFactory, "SwAbstractDialogFactory fail!"); - boost::scoped_ptr<AbstractSwLabDlg> pDlg(pDialogFactory->CreateSwLabDlg(0, aSet, pNewDBMgr, bLabel)); + boost::scoped_ptr<AbstractSwLabDlg> pDlg(pDialogFactory->CreateSwLabDlg(0, aSet, pNewDBMgr.get(), bLabel)); OSL_ENSURE(pDlg, "Dialogdiet fail!"); if ( RET_OK == pDlg->Execute() ) @@ -277,7 +277,7 @@ void SwModule::InsertLab(SfxRequest& rReq, sal_Bool bLabel) pSh->ChgPageDesc( 0, aDesc ); // Insert frame - SwFldMgr* pFldMgr = new SwFldMgr; + boost::scoped_ptr<SwFldMgr> pFldMgr(new SwFldMgr); pFldMgr->SetEvalExpFlds(sal_False); // Prepare border template @@ -377,7 +377,7 @@ void SwModule::InsertLab(SfxRequest& rReq, sal_Bool bLabel) pFldMgr->SetEvalExpFlds(sal_True); pFldMgr->EvalExpFlds(pSh); - delete pFldMgr; + pFldMgr.reset(); if (pFirstFlyFmt) pSh->GotoFly(pFirstFlyFmt->GetName(), FLYCNTTYPE_ALL, sal_False); @@ -400,7 +400,6 @@ void SwModule::InsertLab(SfxRequest& rReq, sal_Bool bLabel) } rReq.SetReturnValue(SfxVoidItem(bLabel ? FN_LABEL : FN_BUSINESS_CARD)); } - delete pNewDBMgr; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx index 8074f8674f94..d3282377d30a 100644 --- a/sw/source/ui/app/docsh2.cxx +++ b/sw/source/ui/app/docsh2.cxx @@ -1433,19 +1433,19 @@ sal_uLong SwDocShell::LoadStylesFromFile( const OUString& rURL, if ( bImport ) { SwRead pRead = ReadXML; - SwReader* pReader = 0; - SwPaM* pPam = 0; + boost::scoped_ptr<SwReader> pReader; + boost::scoped_ptr<SwPaM> pPam; // the SW3IO - Reader need the pam/wrtshell, because only then he // insert the styles! if( bUnoCall ) { SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfContent(), -1 ); - pPam = new SwPaM( aIdx ); - pReader = new SwReader( aMed, rURL, *pPam ); + pPam.reset(new SwPaM( aIdx )); + pReader.reset(new SwReader( aMed, rURL, *pPam )); } else { - pReader = new SwReader( aMed, rURL, *pWrtShell->GetCrsr() ); + pReader.reset(new SwReader( aMed, rURL, *pWrtShell->GetCrsr() )); } pRead->GetReaderOpt().SetTxtFmts( rOpt.IsTxtFmts() ); @@ -1465,8 +1465,6 @@ sal_uLong SwDocShell::LoadStylesFromFile( const OUString& rURL, nErr = pReader->Read( *pRead ); pWrtShell->EndAllAction(); } - delete pPam; - delete pReader; } return nErr; diff --git a/sw/source/ui/dochdl/swdtflvr.cxx b/sw/source/ui/dochdl/swdtflvr.cxx index 326b49296b96..6960868b6fad 100644 --- a/sw/source/ui/dochdl/swdtflvr.cxx +++ b/sw/source/ui/dochdl/swdtflvr.cxx @@ -1160,7 +1160,7 @@ bool SwTransferable::PasteData( TransferableDataHelper& rData, { SwWait aWait( *rSh.GetView(). GetDocShell(), false ); - SwTrnsfrActionAndUndo* pAction = 0; + boost::scoped_ptr<SwTrnsfrActionAndUndo> pAction; SwModule* pMod = SW_MOD(); bool nRet = false; @@ -1214,8 +1214,8 @@ bool SwTransferable::PasteData( TransferableDataHelper& rData, if( bDelSel ) // #i34830# - pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD, NULL, - sal_True ); + pAction.reset(new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD, NULL, + sal_True )); } SwTransferable *pTrans=0, *pTunneledTrans=GetSwTransferable( rData ); @@ -1260,7 +1260,7 @@ bool SwTransferable::PasteData( TransferableDataHelper& rData, { if( !pAction ) { - pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD); + pAction.reset(new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD)); } // in Drag&Drop MessageBoxes must not be showed @@ -1521,7 +1521,7 @@ bool SwTransferable::PasteData( TransferableDataHelper& rData, rSh.GetView().StopShellTimer(); } - delete pAction; + pAction.reset(); if( bCallAutoCaption ) rSh.GetView().AutoCaption( GRAPHIC_CAP ); |