diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-06-24 13:43:40 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-06-25 09:12:06 +0900 |
commit | e32b78ebfd9dc6f780e73d17c794c54828471895 (patch) | |
tree | 2cd7474314572f8217e82f8b757fb1c281499958 /svx | |
parent | 3a7f55924b6901e555621e662cbc4e112396dfb9 (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: I1a566a870a3bde91a527ac454fc9946e99a2593e
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/form/fmshimp.cxx | 10 | ||||
-rw-r--r-- | svx/source/gallery2/codec.cxx | 17 | ||||
-rw-r--r-- | svx/source/gallery2/galbrws1.cxx | 10 | ||||
-rw-r--r-- | svx/source/gallery2/galbrws2.cxx | 4 | ||||
-rw-r--r-- | svx/source/gallery2/galini.cxx | 6 | ||||
-rw-r--r-- | svx/source/gallery2/gallery1.cxx | 9 | ||||
-rw-r--r-- | svx/source/gallery2/galmisc.cxx | 5 | ||||
-rw-r--r-- | svx/source/gallery2/galobj.cxx | 6 |
8 files changed, 30 insertions, 37 deletions
diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx index 73f2f1704765..5c051c3358ba 100644 --- a/svx/source/form/fmshimp.cxx +++ b/svx/source/form/fmshimp.cxx @@ -1600,9 +1600,9 @@ void FmXFormShell::ExecuteSearch() // ausgeraeumt sind, sollte hier ein SM_USETHREAD rein, denn die Suche in einem eigenen Thread ist doch etwas fluessiger // sollte allerdings irgendwie von dem unterliegenden Cursor abhaengig gemacht werden, DAO zum Beispiel ist nicht thread-sicher SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - AbstractFmSearchDialog* pDialog = NULL; + boost::scoped_ptr<AbstractFmSearchDialog> pDialog; if ( pFact ) - pDialog = pFact->CreateFmSearchDialog( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow(), strInitialText, aContextNames, nInitialContext, LINK( this, FmXFormShell, OnSearchContextRequest ) ); + pDialog.reset(pFact->CreateFmSearchDialog( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow(), strInitialText, aContextNames, nInitialContext, LINK( this, FmXFormShell, OnSearchContextRequest ) )); DBG_ASSERT( pDialog, "FmXFormShell::ExecuteSearch: could not create the search dialog!" ); if ( pDialog ) { @@ -1610,7 +1610,7 @@ void FmXFormShell::ExecuteSearch() pDialog->SetFoundHandler( LINK( this, FmXFormShell, OnFoundData ) ); pDialog->SetCanceledNotFoundHdl( LINK( this, FmXFormShell, OnCanceledNotFound ) ); pDialog->Execute(); - delete pDialog; + pDialog.reset(); } // GridControls wieder restaurieren @@ -4101,7 +4101,7 @@ void ControlConversionMenuController::StateChanged(sal_uInt16 nSID, SfxItemState { // We can't simply re-insert the item because we have a clear order for all the our items. // So first we have to determine the position of the item to insert. - PopupMenu* pSource = FmXFormShell::GetConversionMenu(); + boost::scoped_ptr<PopupMenu> pSource(FmXFormShell::GetConversionMenu()); sal_uInt16 nSourcePos = pSource->GetItemPos(nSID); DBG_ASSERT(nSourcePos != MENU_ITEM_NOTFOUND, "ControlConversionMenuController::StateChanged : FmXFormShell supplied an invalid menu !"); sal_uInt16 nPrevInSource = nSourcePos; @@ -4122,8 +4122,6 @@ void ControlConversionMenuController::StateChanged(sal_uInt16 nSID, SfxItemState pSource->GetItemBits(nSID), OString(), ++nPrevInConversion); m_pConversionMenu->SetItemImage(nSID, pSource->GetItemImage(nSID)); m_pConversionMenu->SetHelpId(nSID, pSource->GetHelpId(nSID)); - - delete pSource; } m_pMainMenu->EnableItem(SID_FM_CHANGECONTROLTYPE, m_pConversionMenu->GetItemCount() > 0); } diff --git a/svx/source/gallery2/codec.cxx b/svx/source/gallery2/codec.cxx index 8d3264e355f1..3ef8f1579caa 100644 --- a/svx/source/gallery2/codec.cxx +++ b/svx/source/gallery2/codec.cxx @@ -22,6 +22,7 @@ #include <tools/zcodec.hxx> #include <tools/debug.hxx> #include "codec.hxx" +#include <boost/scoped_array.hpp> // - GalleryCodec - @@ -98,11 +99,12 @@ void GalleryCodec::Read( SvStream& rStmToRead ) // decompress if( 1 == nVersion ) { - sal_uInt8* pCompressedBuffer = new sal_uInt8[ nCompressedSize ]; rStm.Read( pCompressedBuffer, nCompressedSize ); - sal_uInt8* pInBuf = pCompressedBuffer; - sal_uInt8* pOutBuf = new sal_uInt8[ nUnCompressedSize ]; - sal_uInt8* pTmpBuf = pOutBuf; - sal_uInt8* pLast = pOutBuf + nUnCompressedSize - 1; + boost::scoped_array<sal_uInt8> pCompressedBuffer(new sal_uInt8[ nCompressedSize ]); + rStm.Read( pCompressedBuffer.get(), nCompressedSize ); + sal_uInt8* pInBuf = pCompressedBuffer.get(); + boost::scoped_array<sal_uInt8> pOutBuf(new sal_uInt8[ nUnCompressedSize ]); + sal_uInt8* pTmpBuf = pOutBuf.get(); + sal_uInt8* pLast = pOutBuf.get() + nUnCompressedSize - 1; sal_uIntPtr nIndex = 0UL, nCountByte, nRunByte; bool bEndDecoding = false; @@ -138,10 +140,7 @@ void GalleryCodec::Read( SvStream& rStmToRead ) } while ( !bEndDecoding && ( pTmpBuf <= pLast ) ); - rStmToRead.Write( pOutBuf, nUnCompressedSize ); - - delete[] pOutBuf; - delete[] pCompressedBuffer; + rStmToRead.Write( pOutBuf.get(), nUnCompressedSize ); } else if( 2 == nVersion ) { diff --git a/svx/source/gallery2/galbrws1.cxx b/svx/source/gallery2/galbrws1.cxx index ddb56e1d6dd9..0cc404ef81f2 100644 --- a/svx/source/gallery2/galbrws1.cxx +++ b/svx/source/gallery2/galbrws1.cxx @@ -38,6 +38,7 @@ #include <svx/dialmgr.hxx> #include <svx/svxdlg.hxx> +#include <boost/scoped_ptr.hpp> // - Namespaces - @@ -361,13 +362,12 @@ void GalleryBrowser1::ImplExecute( sal_uInt16 nId ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - VclAbstractRefreshableDialog* aActualizeProgress = pFact->CreateActualizeProgressDialog( this, pTheme ); + boost::scoped_ptr<VclAbstractRefreshableDialog> aActualizeProgress(pFact->CreateActualizeProgressDialog( this, pTheme )); DBG_ASSERT(aActualizeProgress, "Dialogdiet fail!"); aActualizeProgress->Update(); aActualizeProgress->Execute(); mpGallery->ReleaseTheme( pTheme, *this ); - delete aActualizeProgress; } } break; @@ -386,7 +386,7 @@ void GalleryBrowser1::ImplExecute( sal_uInt16 nId ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); DBG_ASSERT(pFact, "Dialogdiet fail!"); - AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldName ); + boost::scoped_ptr<AbstractTitleDialog> aDlg(pFact->CreateTitleDialog( this, aOldName )); DBG_ASSERT(aDlg, "Dialogdiet fail!"); if( aDlg->Execute() == RET_OK ) @@ -409,7 +409,6 @@ void GalleryBrowser1::ImplExecute( sal_uInt16 nId ) } } mpGallery->ReleaseTheme( pTheme, *this ); - delete aDlg; } break; @@ -423,12 +422,11 @@ void GalleryBrowser1::ImplExecute( sal_uInt16 nId ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - AbstractGalleryIdDialog* aDlg = pFact->CreateGalleryIdDialog( this, pTheme ); + boost::scoped_ptr<AbstractGalleryIdDialog> aDlg(pFact->CreateGalleryIdDialog( this, pTheme )); DBG_ASSERT(aDlg, "Dialogdiet fail!"); if( aDlg->Execute() == RET_OK ) pTheme->SetId( aDlg->GetId(), true ); - delete aDlg; } } diff --git a/svx/source/gallery2/galbrws2.cxx b/svx/source/gallery2/galbrws2.cxx index 20e0ef7b3fe7..af7335bf8415 100644 --- a/svx/source/gallery2/galbrws2.cxx +++ b/svx/source/gallery2/galbrws2.cxx @@ -57,6 +57,7 @@ #include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/style/GraphicLocation.hpp> #include <map> +#include <boost/scoped_ptr.hpp> #undef GALLERY_USE_CLIPBOARD @@ -1205,7 +1206,7 @@ void GalleryBrowser2::Execute( sal_uInt16 nId ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldTitle ); + boost::scoped_ptr<AbstractTitleDialog> aDlg(pFact->CreateTitleDialog( this, aOldTitle )); DBG_ASSERT(aDlg, "Dialogdiet fail!"); if( aDlg->Execute() == RET_OK ) { @@ -1222,7 +1223,6 @@ void GalleryBrowser2::Execute( sal_uInt16 nId ) } mpCurTheme->ReleaseObject( pObj ); - delete aDlg; } } } diff --git a/svx/source/gallery2/galini.cxx b/svx/source/gallery2/galini.cxx index 090b086565fe..b4c53388cf1c 100644 --- a/svx/source/gallery2/galini.cxx +++ b/svx/source/gallery2/galini.cxx @@ -23,12 +23,13 @@ #include <unotools/syslocale.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> +#include <boost/scoped_ptr.hpp> OUString GalleryThemeEntry::ReadStrFromIni(const OUString &aKeyName ) { - SvStream *pStrm = ::utl::UcbStreamHelper::CreateStream( + boost::scoped_ptr<SvStream> pStrm(::utl::UcbStreamHelper::CreateStream( GetStrURL().GetMainURL( INetURLObject::NO_DECODE ), - STREAM_READ ); + STREAM_READ )); const LanguageTag &rLangTag = Application::GetSettings().GetUILanguageTag(); @@ -86,7 +87,6 @@ OUString GalleryThemeEntry::ReadStrFromIni(const OUString &aKeyName ) } } } - delete pStrm; } SAL_INFO( "svx", "readStrFromIni returns '" << aResult << "'"); diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx index 8d3024f8c217..20fa438bad1f 100644 --- a/svx/source/gallery2/gallery1.cxx +++ b/svx/source/gallery2/gallery1.cxx @@ -34,6 +34,7 @@ #include "svx/gallery1.hxx" #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/ucb/XContentAccess.hpp> +#include <boost/scoped_ptr.hpp> // - Namespaces - @@ -242,7 +243,7 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO OUString aTestFile( "cdefghij.klm" ); aTestURL.Append( aTestFile ); - SvStream* pTestStm = ::utl::UcbStreamHelper::CreateStream( aTestURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE ); + boost::scoped_ptr<SvStream> pTestStm(::utl::UcbStreamHelper::CreateStream( aTestURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE )); if( pTestStm ) { @@ -251,7 +252,7 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO if( pTestStm->GetError() ) rbDirIsReadOnly = true; - delete pTestStm; + pTestStm.reset(); KillFile( aTestURL ); } else @@ -601,7 +602,7 @@ GalleryTheme* Gallery::ImplGetCachedTheme(const GalleryThemeEntry* pThemeEntry) if( FileExists( aURL ) ) { - SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); + boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ )); if( pIStm ) { @@ -618,8 +619,6 @@ GalleryTheme* Gallery::ImplGetCachedTheme(const GalleryThemeEntry* pThemeEntry) catch (const css::ucb::ContentCreationException&) { } - - delete pIStm; } } diff --git a/svx/source/gallery2/galmisc.cxx b/svx/source/gallery2/galmisc.cxx index 47b05eabaccd..9ec75fe04a86 100644 --- a/svx/source/gallery2/galmisc.cxx +++ b/svx/source/gallery2/galmisc.cxx @@ -47,6 +47,7 @@ #include <com/sun/star/ucb/XContentAccess.hpp> #include <com/sun/star/ucb/TransferInfo.hpp> #include <com/sun/star/ucb/NameClash.hpp> +#include <boost/scoped_ptr.hpp> using namespace ::rtl; using namespace ::com::sun::star; @@ -95,7 +96,7 @@ sal_uInt16 GalleryGraphicImport( const INetURLObject& rURL, Graphic& rGraphic, if( pIStm ) { GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); - GalleryProgress* pProgress = bShowProgress ? new GalleryProgress( &rGraphicFilter ) : NULL; + boost::scoped_ptr<GalleryProgress> pProgress(bShowProgress ? new GalleryProgress( &rGraphicFilter ) : NULL); sal_uInt16 nFormat; if( !rGraphicFilter.ImportGraphic( rGraphic, rURL.GetMainURL( INetURLObject::NO_DECODE ), *pIStm, GRFILTER_FORMAT_DONTKNOW, &nFormat ) ) @@ -103,8 +104,6 @@ sal_uInt16 GalleryGraphicImport( const INetURLObject& rURL, Graphic& rGraphic, rFilterName = rGraphicFilter.GetImportFormatName( nFormat ); nRet = SGA_IMPORT_FILE; } - - delete pProgress; } return nRet; diff --git a/svx/source/gallery2/galobj.cxx b/svx/source/gallery2/galobj.cxx index 70196d448241..87686f867d3e 100644 --- a/svx/source/gallery2/galobj.cxx +++ b/svx/source/gallery2/galobj.cxx @@ -39,6 +39,7 @@ #include <vcl/settings.hxx> #include <vcl/dibtools.hxx> #include "gallerydrawmodel.hxx" +#include <boost/scoped_ptr.hpp> using namespace ::com::sun::star; @@ -230,8 +231,8 @@ const OUString SgaObject::GetTitle() const !aResourceName.isEmpty() && ( nResId > 0 ) && ( nResId < 0x10000 ) ) { OString aMgrName(OUStringToOString(aResourceName, RTL_TEXTENCODING_UTF8)); - ResMgr* pResMgr = ResMgr::CreateResMgr( aMgrName.getStr(), - Application::GetSettings().GetUILanguageTag() ); + boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( aMgrName.getStr(), + Application::GetSettings().GetUILanguageTag() )); if ( pResMgr ) { ResId aResId( (sal_uInt16)nResId, *pResMgr ); @@ -240,7 +241,6 @@ const OUString SgaObject::GetTitle() const { aReturnValue = aResId.toString(); } - delete pResMgr; } } } |