summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-06-20 06:54:55 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-06-20 10:20:39 +0900
commit67f64c266cd5a0368eff0be727228bc6a9c67cb2 (patch)
treeb54b9cf8371b834631a617baf9b85a33d51b2452 /sw
parentd77c108922f7ea2c57bc63bbe289bba92f6213a6 (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: Ic9b9c22c0ad15bfefce729e7277f950cb66d9bf6
Diffstat (limited to 'sw')
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx9
-rw-r--r--sw/source/uibase/utlui/content.cxx4
-rw-r--r--sw/source/uibase/utlui/glbltree.cxx31
-rw-r--r--sw/source/uibase/utlui/navipi.cxx9
-rw-r--r--sw/source/uibase/utlui/numfmtlb.cxx7
5 files changed, 28 insertions, 32 deletions
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index cc8e06692e1b..a10d2c68a24e 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -134,6 +134,7 @@
#include <svx/svdview.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::text;
@@ -922,12 +923,11 @@ Reference< XIndexAccess >
Reference< XInterface > xTmp;
sal_Int32 nResult = 0;
Reference< XTextCursor > xCrsr;
- SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, true, nResult, xTmp);
+ boost::scoped_ptr<SwUnoCrsr> pResultCrsr(FindAny(xDesc, xCrsr, true, nResult, xTmp));
if(!pResultCrsr)
throw RuntimeException();
Reference< XIndexAccess > xRet;
- xRet = new SwXTextRanges( (nResult) ? pResultCrsr : 0 );
- delete pResultCrsr;
+ xRet = new SwXTextRanges( (nResult) ? pResultCrsr.get() : 0 );
return xRet;
}
@@ -1985,10 +1985,9 @@ void SwXTextDocument::setPropertyValue(const OUString& rPropertyName, const Any&
default:
{
const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
- SfxPoolItem* pNewItem = rItem.Clone();
+ boost::scoped_ptr<SfxPoolItem> pNewItem(rItem.Clone());
pNewItem->PutValue(aValue, pEntry->nMemberId);
pDocShell->GetDoc()->SetDefault(*pNewItem);
- delete pNewItem;
}
}
}
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index e6a827e98f41..57634f048e62 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -88,6 +88,7 @@
#include <unomid.h>
#include "navmgr.hxx"
+#include <boost/scoped_ptr.hpp>
#define CTYPE_CNT 0
#define CTYPE_CTT 1
@@ -3256,7 +3257,7 @@ void SwContentTree::EditEntry(SvTreeListEntry* pEntry, sal_uInt8 nMode)
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
- AbstractSwRenameXNamedDlg* pDlg = pFact->CreateSwRenameXNamedDlg(this, xNamed, xNameAccess);
+ boost::scoped_ptr<AbstractSwRenameXNamedDlg> pDlg(pFact->CreateSwRenameXNamedDlg(this, xNamed, xNameAccess));
OSL_ENSURE(pDlg, "Dialogdiet fail!");
if(xSecond.is())
pDlg->SetAlternativeAccess( xSecond, xThird);
@@ -3272,7 +3273,6 @@ void SwContentTree::EditEntry(SvTreeListEntry* pEntry, sal_uInt8 nMode)
}
pDlg->SetForbiddenChars(sForbiddenChars);
pDlg->Execute();
- delete pDlg;
}
}
diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx
index 9da3e4c7a2ff..12bcf3c7993e 100644
--- a/sw/source/uibase/utlui/glbltree.cxx
+++ b/sw/source/uibase/utlui/glbltree.cxx
@@ -57,6 +57,7 @@
#include <comcore.hrc>
#include <globals.hrc>
#include "swabstdlg.hxx"
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::uno;
@@ -215,7 +216,7 @@ sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
if( aData.HasFormat( FORMAT_FILE_LIST ))
{
nRet = rEvt.mnAction;
- SwGlblDocContents* pTempContents = new SwGlblDocContents;
+ boost::scoped_ptr<SwGlblDocContents> pTempContents(new SwGlblDocContents);
int nAbsContPos = pDropEntry ?
(int) GetModel()->GetAbsPos(pDropEntry):
- 1;
@@ -243,7 +244,6 @@ sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
}
}
}
- delete pTempContents;
}
else if( !(sFileName =
SwNavigationPI::CreateDropFileName( aData )).isEmpty())
@@ -385,7 +385,7 @@ void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
sal_uInt16 nEnableFlags = GetEnableFlags();
if(FN_GLOBAL_OPEN == nTbxId)
{
- PopupMenu *pMenu = new PopupMenu;
+ boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; i++)
{
pMenu->InsertItem( i, aContextStrings[ST_INDEX - ST_GLOBAL_CONTEXT_FIRST - CTX_INSERT_ANY_INDEX + i] );
@@ -397,13 +397,13 @@ void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
pMenu->EnableItem(CTX_INSERT_NEW_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
- delete pMenu;
+ pMenu.reset();
pBox->EndSelection();
pBox->Invalidate();
}
else if(FN_GLOBAL_UPDATE == nTbxId)
{
- PopupMenu *pMenu = new PopupMenu;
+ boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
{
pMenu->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
@@ -412,7 +412,7 @@ void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
pMenu->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
- delete pMenu;
+ pMenu.reset();
pBox->EndSelection();
pBox->Invalidate();
}
@@ -846,7 +846,7 @@ void SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry
// must be refilled. So you do not have to remember anything,
// deleting begins at the end.
SvTreeListEntry* pSelEntry = LastSelected();
- SwGlblDocContents* pTempContents = 0;
+ boost::scoped_ptr<SwGlblDocContents> pTempContents;
pActiveShell->StartAction();
while(pSelEntry)
{
@@ -856,12 +856,11 @@ void SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry
pSelEntry = PrevSelected(pSelEntry);
if(pSelEntry)
{
- delete pTempContents;
- pTempContents = new SwGlblDocContents;
+ pTempContents.reset(new SwGlblDocContents);
pActiveShell->GetGlobalDocContent(*pTempContents);
}
}
- delete pTempContents;
+ pTempContents.reset();
pActiveShell->EndAction();
pCont = 0;
}
@@ -881,12 +880,12 @@ void SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "Dialogdiet fail!");
- AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog(
+ boost::scoped_ptr<AbstractMultiTOXTabDialog> pDlg(pFact->CreateMultiTOXTabDialog(
this, aSet,
*pActiveShell,
0,
USHRT_MAX,
- true);
+ true));
OSL_ENSURE(pDlg, "Dialogdiet fail!");
if(RET_OK == pDlg->Execute())
{
@@ -898,7 +897,6 @@ void SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry
pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
}
pCont = 0;
- delete pDlg;
}
}
break;
@@ -1104,7 +1102,7 @@ bool SwGlobalTree::Update(bool bHard)
else
{
bool bCopy = false;
- SwGlblDocContents* pTempContents = new SwGlblDocContents;
+ boost::scoped_ptr<SwGlblDocContents> pTempContents(new SwGlblDocContents);
pActiveShell->GetGlobalDocContent(*pTempContents);
if(pTempContents->size() != pSwGlblDocContents->size() ||
pTempContents->size() != GetEntryCount())
@@ -1144,7 +1142,6 @@ bool SwGlobalTree::Update(bool bHard)
pTempContents->clear();
}
- delete pTempContents;
}
}
@@ -1353,7 +1350,7 @@ IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
Application::SetDefDialogParent( pDefParentWin );
if ( ERRCODE_NONE == _pFileDlg->GetError() )
{
- SfxMediumList* pMedList = pDocInserter->CreateMediumList();
+ boost::scoped_ptr<SfxMediumList> pMedList(pDocInserter->CreateMediumList());
if ( pMedList )
{
Sequence< OUString >aFileNames( pMedList->size() );
@@ -1368,7 +1365,7 @@ IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
sFileName += OUString(sfx2::cTokenSeparator);
pFileNames[nPos++] = sFileName;
}
- delete pMedList;
+ pMedList.reset();
InsertRegion( pDocContent, aFileNames );
DELETEZ( pDocContent );
}
diff --git a/sw/source/uibase/utlui/navipi.cxx b/sw/source/uibase/utlui/navipi.cxx
index ff5dfc8b2628..b9e50d72c2d0 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -54,6 +54,7 @@
#include "access.hrc"
#include <unomid.h>
+#include <boost/scoped_ptr.hpp>
#define PAGE_CHANGE_TIMEOUT 1000
@@ -371,7 +372,7 @@ IMPL_LINK( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox )
HID_NAVI_DRAG_LINK,
HID_NAVI_DRAG_COPY,
};
- PopupMenu *pMenu = new PopupMenu;
+ boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
for (sal_uInt16 i = 0; i <= REGION_MODE_EMBEDDED; i++)
{
pMenu->InsertItem( i + 1, aContextArr[i] );
@@ -385,13 +386,13 @@ IMPL_LINK( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox )
POPUPMENU_EXECUTE_DOWN );
pBox->SetItemDown( nCurrItemId, false );
pBox->EndSelection();
- delete pMenu;
+ pMenu.reset();
pBox->Invalidate();
}
break;
case FN_OUTLINE_LEVEL:
{
- PopupMenu *pMenu = new PopupMenu;
+ boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
for (sal_uInt16 i = 101; i <= 100 + MAXLEVEL; i++)
{
pMenu->InsertItem( i, OUString::number(i - 100) );
@@ -404,7 +405,7 @@ IMPL_LINK( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox )
pBox->GetItemRect(FN_OUTLINE_LEVEL),
POPUPMENU_EXECUTE_DOWN );
pBox->SetItemDown( nCurrItemId, false );
- delete pMenu;
+ pMenu.reset();
pBox->EndSelection();
pBox->Invalidate();
}
diff --git a/sw/source/uibase/utlui/numfmtlb.cxx b/sw/source/uibase/utlui/numfmtlb.cxx
index 55ac0d15725d..b3e37525f82a 100644
--- a/sw/source/uibase/utlui/numfmtlb.cxx
+++ b/sw/source/uibase/utlui/numfmtlb.cxx
@@ -41,6 +41,7 @@
#include "dialog.hrc"
#include <unomid.h>
#include <sfx2/viewfrm.hxx>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
@@ -395,9 +396,9 @@ IMPL_LINK( NumFormatListBox, SelectHdl, ListBox *, pBox )
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
- SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aCoreSet,
+ boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( this, aCoreSet,
GetView()->GetViewFrame()->GetFrame().GetFrameInterface(),
- RC_DLG_SWNUMFMTDLG );
+ RC_DLG_SWNUMFMTDLG ));
OSL_ENSURE(pDlg, "Dialogdiet fail!");
if (RET_OK == pDlg->Execute())
@@ -433,8 +434,6 @@ IMPL_LINK( NumFormatListBox, SelectHdl, ListBox *, pBox )
}
else
SetDefFormat(nFormat);
-
- delete pDlg;
}
return 0;
}