summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-05-14 14:52:56 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-05-14 15:09:55 +0900
commitdecfecc3d2414a6467bae6d5e9069fb63885e3fe (patch)
tree608a18ca59e97d5d136bf9d5d046541eed2f0907
parent146f6e7e68ea56f79b72047b97bd9fba66db499d (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: Ib74c40bb4ac11edf97b6843e983a911308fa4b98
-rw-r--r--sc/source/ui/view/gridwin.cxx7
-rw-r--r--sc/source/ui/view/gridwin2.cxx6
-rw-r--r--sc/source/ui/view/gridwin4.cxx12
-rw-r--r--sc/source/ui/view/output.cxx12
-rw-r--r--sc/source/ui/view/output2.cxx14
5 files changed, 23 insertions, 28 deletions
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index d1194bfe4075..2226ab176caf 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -1262,15 +1262,15 @@ void ScGridWindow::LaunchDataSelectMenu( SCCOL nCol, SCROW nRow, bool bDataSelec
const ScValidationData* pData = pDoc->GetValidationEntry( nIndex );
if (pData)
{
- ScTypedStrData* pNew = NULL;
+ boost::scoped_ptr<ScTypedStrData> pNew;
OUString aDocStr = pDoc->GetString(nCol, nRow, nTab);
if ( pDoc->HasValueData( nCol, nRow, nTab ) )
{
double fVal = pDoc->GetValue(ScAddress(nCol, nRow, nTab));
- pNew = new ScTypedStrData(aDocStr, fVal, ScTypedStrData::Value);
+ pNew.reset(new ScTypedStrData(aDocStr, fVal, ScTypedStrData::Value));
}
else
- pNew = new ScTypedStrData(aDocStr, 0.0, ScTypedStrData::Standard);
+ pNew.reset(new ScTypedStrData(aDocStr, 0.0, ScTypedStrData::Standard));
bool bSortList = ( pData->GetListType() == ValidListType::SORTEDASCENDING);
if ( bSortList )
@@ -1293,7 +1293,6 @@ void ScGridWindow::LaunchDataSelectMenu( SCCOL nCol, SCROW nRow, bool bDataSelec
nSelPos = std::distance(itBeg, it);
}
}
- delete pNew;
}
}
}
diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index 6ea8c8906977..357b4191b7a3 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -47,6 +47,7 @@
#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
#include <vector>
+#include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp>
using namespace com::sun::star;
@@ -210,8 +211,8 @@ void ScGridWindow::DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent&
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
- AbstractScPivotFilterDlg* pDlg = pFact->CreateScPivotFilterDlg(
- pViewData->GetViewShell()->GetDialogParent(), aArgSet, nSrcTab);
+ boost::scoped_ptr<AbstractScPivotFilterDlg> pDlg(pFact->CreateScPivotFilterDlg(
+ pViewData->GetViewShell()->GetDialogParent(), aArgSet, nSrcTab));
OSL_ENSURE(pDlg, "Dialog create fail!");
if ( pDlg->Execute() == RET_OK )
{
@@ -228,7 +229,6 @@ void ScGridWindow::DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent&
aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false );
pViewData->GetView()->CursorPosChanged(); // shells may be switched
}
- delete pDlg;
}
}
else
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 5405b898023e..2625a96376dc 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -917,7 +917,7 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
}
Font aFont;
- ScEditEngineDefaulter* pEditEng = NULL;
+ boost::scoped_ptr<ScEditEngineDefaulter> pEditEng;
const ScPatternAttr& rDefPattern = ((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN));
if ( nPageScript == SCRIPTTYPE_LATIN )
{
@@ -929,7 +929,7 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
else
{
// use EditEngine to draw mixed-script string
- pEditEng = new ScEditEngineDefaulter( EditEngine::CreatePool(), true );
+ pEditEng.reset(new ScEditEngineDefaulter( EditEngine::CreatePool(), true ));
pEditEng->SetRefMapMode( pContentDev->GetMapMode() );
SfxItemSet* pEditDefaults = new SfxItemSet( pEditEng->GetEmptyItemSet() );
rDefPattern.FillEditItemSet( pEditDefaults );
@@ -1093,8 +1093,6 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
}
}
}
-
- delete pEditEng;
}
}
@@ -1111,7 +1109,7 @@ void ScGridWindow::DrawButtons( SCCOL nX1, SCCOL nX2, ScTableInfo& rTabInfo, Out
SCSIZE nQuery;
SCTAB nTab = pViewData->GetTabNo();
ScDBData* pDBData = NULL;
- ScQueryParam* pQueryParam = NULL;
+ boost::scoped_ptr<ScQueryParam> pQueryParam;
RowInfo* pRowInfo = rTabInfo.mpRowInfo;
sal_uInt16 nArrCount = rTabInfo.mnArrCount;
@@ -1138,7 +1136,7 @@ void ScGridWindow::DrawButtons( SCCOL nX1, SCCOL nX2, ScTableInfo& rTabInfo, Out
if ( pInfo->bAutoFilter && !pInfo->bHOverlapped )
{
if (!pQueryParam)
- pQueryParam = new ScQueryParam;
+ pQueryParam.reset(new ScQueryParam);
bool bNewData = true;
if (pDBData)
@@ -1249,7 +1247,7 @@ void ScGridWindow::DrawButtons( SCCOL nX1, SCCOL nX2, ScTableInfo& rTabInfo, Out
}
}
- delete pQueryParam;
+ pQueryParam.reset();
aComboButton.SetOutputDevice( this );
}
diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index 6dae6ef6d1ed..5fd547f15a19 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -69,6 +69,7 @@
#include <map>
#include <utility>
#include <iostream>
+#include <boost/scoped_ptr.hpp>
using namespace com::sun::star;
@@ -1368,7 +1369,7 @@ void ScOutputData::DrawFrame()
// draw only rows with set RowInfo::bChanged flag
size_t nRow1 = nFirstRow;
- drawinglayer::processor2d::BaseProcessor2D* pProcessor = CreateProcessor2D();
+ boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(CreateProcessor2D());
if (!pProcessor)
return;
@@ -1379,12 +1380,11 @@ void ScOutputData::DrawFrame()
{
size_t nRow2 = nRow1;
while( (nRow2 + 1 <= nLastRow) && pRowInfo[ nRow2 + 1 ].bChanged ) ++nRow2;
- rArray.DrawRange( pProcessor, nFirstCol, nRow1, nLastCol, nRow2, pForceColor );
+ rArray.DrawRange( pProcessor.get(), nFirstCol, nRow1, nLastCol, nRow2, pForceColor );
nRow1 = nRow2 + 1;
}
}
- if ( pProcessor )
- delete pProcessor;
+ pProcessor.reset();
mpDev->SetDrawMode(nOldDrawMode);
}
@@ -1493,7 +1493,7 @@ void ScOutputData::DrawRotatedFrame( const Color* pForceColor )
mpDev->SetClipRegion( Region( aClipRect ) );
svx::frame::Array& rArray = mrTabInfo.maArray;
- drawinglayer::processor2d::BaseProcessor2D* pProcessor = CreateProcessor2D( );
+ boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(CreateProcessor2D( ));
long nPosY = nScrY;
for (SCSIZE nArrY=1; nArrY<nArrCount; nArrY++)
@@ -1798,7 +1798,7 @@ void ScOutputData::DrawRotatedFrame( const Color* pForceColor )
nPosY += nRowHeight;
}
- if ( pProcessor ) delete pProcessor;
+ pProcessor.reset();
if (bMetaFile)
mpDev->Pop();
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index c0d6473fdccb..6a1bbf184b07 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -4476,7 +4476,7 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)
void ScOutputData::DrawEdit(bool bPixelToLogic)
{
- ScFieldEditEngine* pEngine = NULL;
+ boost::scoped_ptr<ScFieldEditEngine> pEngine;
bool bHyphenatorSet = false;
const ScPatternAttr* pOldPattern = NULL;
const SfxItemSet* pOldCondSet = NULL;
@@ -4592,7 +4592,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
}
SfxItemSet* pPreviewFontSet = mpDoc->GetPreviewFont( nCellX, nCellY, nTab );
if (!pEngine)
- pEngine = CreateOutputEditEngine();
+ pEngine.reset(CreateOutputEditEngine());
else
lcl_ClearEdit( *pEngine ); // also calls SetUpdateMode(sal_False)
@@ -4606,7 +4606,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
SVX_HOR_JUSTIFY_BLOCK : aParam.meHorJustContext;
aParam.mbPixelToLogic = bPixelToLogic;
aParam.mbHyphenatorSet = bHyphenatorSet;
- aParam.mpEngine = pEngine;
+ aParam.mpEngine = pEngine.get();
aParam.maCell = aCell;
aParam.mnArrY = nArrY;
aParam.mnX = nX;
@@ -4660,7 +4660,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
nRowPosY += pRowInfo[nArrY].nHeight;
}
- delete pEngine;
+ pEngine.reset();
if (bAnyRotated)
DrawRotated(bPixelToLogic); //! von aussen rufen ?
@@ -4680,7 +4680,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
bool bCellContrast = mbUseStyleColor &&
Application::GetSettings().GetStyleSettings().GetHighContrastMode();
- ScFieldEditEngine* pEngine = NULL;
+ boost::scoped_ptr<ScFieldEditEngine> pEngine;
bool bHyphenatorSet = false;
const ScPatternAttr* pPattern;
const SfxItemSet* pCondSet;
@@ -4722,7 +4722,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
if (!bHidden)
{
if (!pEngine)
- pEngine = CreateOutputEditEngine();
+ pEngine.reset(CreateOutputEditEngine());
else
lcl_ClearEdit( *pEngine ); // also calls SetUpdateMode(sal_False)
@@ -5334,8 +5334,6 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
}
nRowPosY += pRowInfo[nArrY].nHeight;
}
-
- delete pEngine;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */