Avoid possible memory leaks in case of exceptions

Change-Id: Ib74c40bb4ac11edf97b6843e983a911308fa4b98
This commit is contained in:
Takeshi Abe
2014-05-14 14:52:56 +09:00
parent 146f6e7e68
commit decfecc3d2
5 changed files with 23 additions and 28 deletions

View File

@@ -1262,15 +1262,15 @@ void ScGridWindow::LaunchDataSelectMenu( SCCOL nCol, SCROW nRow, bool bDataSelec
const ScValidationData* pData = pDoc->GetValidationEntry( nIndex ); const ScValidationData* pData = pDoc->GetValidationEntry( nIndex );
if (pData) if (pData)
{ {
ScTypedStrData* pNew = NULL; boost::scoped_ptr<ScTypedStrData> pNew;
OUString aDocStr = pDoc->GetString(nCol, nRow, nTab); OUString aDocStr = pDoc->GetString(nCol, nRow, nTab);
if ( pDoc->HasValueData( nCol, nRow, nTab ) ) if ( pDoc->HasValueData( nCol, nRow, nTab ) )
{ {
double fVal = pDoc->GetValue(ScAddress(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 else
pNew = new ScTypedStrData(aDocStr, 0.0, ScTypedStrData::Standard); pNew.reset(new ScTypedStrData(aDocStr, 0.0, ScTypedStrData::Standard));
bool bSortList = ( pData->GetListType() == ValidListType::SORTEDASCENDING); bool bSortList = ( pData->GetListType() == ValidListType::SORTEDASCENDING);
if ( bSortList ) if ( bSortList )
@@ -1293,7 +1293,6 @@ void ScGridWindow::LaunchDataSelectMenu( SCCOL nCol, SCROW nRow, bool bDataSelec
nSelPos = std::distance(itBeg, it); nSelPos = std::distance(itBeg, it);
} }
} }
delete pNew;
} }
} }
} }

View File

@@ -47,6 +47,7 @@
#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
#include <vector> #include <vector>
#include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
using namespace com::sun::star; using namespace com::sun::star;
@@ -210,8 +211,8 @@ void ScGridWindow::DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent&
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
AbstractScPivotFilterDlg* pDlg = pFact->CreateScPivotFilterDlg( boost::scoped_ptr<AbstractScPivotFilterDlg> pDlg(pFact->CreateScPivotFilterDlg(
pViewData->GetViewShell()->GetDialogParent(), aArgSet, nSrcTab); pViewData->GetViewShell()->GetDialogParent(), aArgSet, nSrcTab));
OSL_ENSURE(pDlg, "Dialog create fail!"); OSL_ENSURE(pDlg, "Dialog create fail!");
if ( pDlg->Execute() == RET_OK ) if ( pDlg->Execute() == RET_OK )
{ {
@@ -228,7 +229,6 @@ void ScGridWindow::DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent&
aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false ); aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false );
pViewData->GetView()->CursorPosChanged(); // shells may be switched pViewData->GetView()->CursorPosChanged(); // shells may be switched
} }
delete pDlg;
} }
} }
else else

View File

@@ -917,7 +917,7 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
} }
Font aFont; Font aFont;
ScEditEngineDefaulter* pEditEng = NULL; boost::scoped_ptr<ScEditEngineDefaulter> pEditEng;
const ScPatternAttr& rDefPattern = ((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN)); const ScPatternAttr& rDefPattern = ((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN));
if ( nPageScript == SCRIPTTYPE_LATIN ) if ( nPageScript == SCRIPTTYPE_LATIN )
{ {
@@ -929,7 +929,7 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
else else
{ {
// use EditEngine to draw mixed-script string // use EditEngine to draw mixed-script string
pEditEng = new ScEditEngineDefaulter( EditEngine::CreatePool(), true ); pEditEng.reset(new ScEditEngineDefaulter( EditEngine::CreatePool(), true ));
pEditEng->SetRefMapMode( pContentDev->GetMapMode() ); pEditEng->SetRefMapMode( pContentDev->GetMapMode() );
SfxItemSet* pEditDefaults = new SfxItemSet( pEditEng->GetEmptyItemSet() ); SfxItemSet* pEditDefaults = new SfxItemSet( pEditEng->GetEmptyItemSet() );
rDefPattern.FillEditItemSet( pEditDefaults ); 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; SCSIZE nQuery;
SCTAB nTab = pViewData->GetTabNo(); SCTAB nTab = pViewData->GetTabNo();
ScDBData* pDBData = NULL; ScDBData* pDBData = NULL;
ScQueryParam* pQueryParam = NULL; boost::scoped_ptr<ScQueryParam> pQueryParam;
RowInfo* pRowInfo = rTabInfo.mpRowInfo; RowInfo* pRowInfo = rTabInfo.mpRowInfo;
sal_uInt16 nArrCount = rTabInfo.mnArrCount; 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 ( pInfo->bAutoFilter && !pInfo->bHOverlapped )
{ {
if (!pQueryParam) if (!pQueryParam)
pQueryParam = new ScQueryParam; pQueryParam.reset(new ScQueryParam);
bool bNewData = true; bool bNewData = true;
if (pDBData) if (pDBData)
@@ -1249,7 +1247,7 @@ void ScGridWindow::DrawButtons( SCCOL nX1, SCCOL nX2, ScTableInfo& rTabInfo, Out
} }
} }
delete pQueryParam; pQueryParam.reset();
aComboButton.SetOutputDevice( this ); aComboButton.SetOutputDevice( this );
} }

View File

@@ -69,6 +69,7 @@
#include <map> #include <map>
#include <utility> #include <utility>
#include <iostream> #include <iostream>
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star; using namespace com::sun::star;
@@ -1368,7 +1369,7 @@ void ScOutputData::DrawFrame()
// draw only rows with set RowInfo::bChanged flag // draw only rows with set RowInfo::bChanged flag
size_t nRow1 = nFirstRow; size_t nRow1 = nFirstRow;
drawinglayer::processor2d::BaseProcessor2D* pProcessor = CreateProcessor2D(); boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(CreateProcessor2D());
if (!pProcessor) if (!pProcessor)
return; return;
@@ -1379,12 +1380,11 @@ void ScOutputData::DrawFrame()
{ {
size_t nRow2 = nRow1; size_t nRow2 = nRow1;
while( (nRow2 + 1 <= nLastRow) && pRowInfo[ nRow2 + 1 ].bChanged ) ++nRow2; 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; nRow1 = nRow2 + 1;
} }
} }
if ( pProcessor ) pProcessor.reset();
delete pProcessor;
mpDev->SetDrawMode(nOldDrawMode); mpDev->SetDrawMode(nOldDrawMode);
} }
@@ -1493,7 +1493,7 @@ void ScOutputData::DrawRotatedFrame( const Color* pForceColor )
mpDev->SetClipRegion( Region( aClipRect ) ); mpDev->SetClipRegion( Region( aClipRect ) );
svx::frame::Array& rArray = mrTabInfo.maArray; svx::frame::Array& rArray = mrTabInfo.maArray;
drawinglayer::processor2d::BaseProcessor2D* pProcessor = CreateProcessor2D( ); boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(CreateProcessor2D( ));
long nPosY = nScrY; long nPosY = nScrY;
for (SCSIZE nArrY=1; nArrY<nArrCount; nArrY++) for (SCSIZE nArrY=1; nArrY<nArrCount; nArrY++)
@@ -1798,7 +1798,7 @@ void ScOutputData::DrawRotatedFrame( const Color* pForceColor )
nPosY += nRowHeight; nPosY += nRowHeight;
} }
if ( pProcessor ) delete pProcessor; pProcessor.reset();
if (bMetaFile) if (bMetaFile)
mpDev->Pop(); mpDev->Pop();

View File

@@ -4476,7 +4476,7 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)
void ScOutputData::DrawEdit(bool bPixelToLogic) void ScOutputData::DrawEdit(bool bPixelToLogic)
{ {
ScFieldEditEngine* pEngine = NULL; boost::scoped_ptr<ScFieldEditEngine> pEngine;
bool bHyphenatorSet = false; bool bHyphenatorSet = false;
const ScPatternAttr* pOldPattern = NULL; const ScPatternAttr* pOldPattern = NULL;
const SfxItemSet* pOldCondSet = NULL; const SfxItemSet* pOldCondSet = NULL;
@@ -4592,7 +4592,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
} }
SfxItemSet* pPreviewFontSet = mpDoc->GetPreviewFont( nCellX, nCellY, nTab ); SfxItemSet* pPreviewFontSet = mpDoc->GetPreviewFont( nCellX, nCellY, nTab );
if (!pEngine) if (!pEngine)
pEngine = CreateOutputEditEngine(); pEngine.reset(CreateOutputEditEngine());
else else
lcl_ClearEdit( *pEngine ); // also calls SetUpdateMode(sal_False) lcl_ClearEdit( *pEngine ); // also calls SetUpdateMode(sal_False)
@@ -4606,7 +4606,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
SVX_HOR_JUSTIFY_BLOCK : aParam.meHorJustContext; SVX_HOR_JUSTIFY_BLOCK : aParam.meHorJustContext;
aParam.mbPixelToLogic = bPixelToLogic; aParam.mbPixelToLogic = bPixelToLogic;
aParam.mbHyphenatorSet = bHyphenatorSet; aParam.mbHyphenatorSet = bHyphenatorSet;
aParam.mpEngine = pEngine; aParam.mpEngine = pEngine.get();
aParam.maCell = aCell; aParam.maCell = aCell;
aParam.mnArrY = nArrY; aParam.mnArrY = nArrY;
aParam.mnX = nX; aParam.mnX = nX;
@@ -4660,7 +4660,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
nRowPosY += pRowInfo[nArrY].nHeight; nRowPosY += pRowInfo[nArrY].nHeight;
} }
delete pEngine; pEngine.reset();
if (bAnyRotated) if (bAnyRotated)
DrawRotated(bPixelToLogic); //! von aussen rufen ? DrawRotated(bPixelToLogic); //! von aussen rufen ?
@@ -4680,7 +4680,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
bool bCellContrast = mbUseStyleColor && bool bCellContrast = mbUseStyleColor &&
Application::GetSettings().GetStyleSettings().GetHighContrastMode(); Application::GetSettings().GetStyleSettings().GetHighContrastMode();
ScFieldEditEngine* pEngine = NULL; boost::scoped_ptr<ScFieldEditEngine> pEngine;
bool bHyphenatorSet = false; bool bHyphenatorSet = false;
const ScPatternAttr* pPattern; const ScPatternAttr* pPattern;
const SfxItemSet* pCondSet; const SfxItemSet* pCondSet;
@@ -4722,7 +4722,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
if (!bHidden) if (!bHidden)
{ {
if (!pEngine) if (!pEngine)
pEngine = CreateOutputEditEngine(); pEngine.reset(CreateOutputEditEngine());
else else
lcl_ClearEdit( *pEngine ); // also calls SetUpdateMode(sal_False) lcl_ClearEdit( *pEngine ); // also calls SetUpdateMode(sal_False)
@@ -5334,8 +5334,6 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
} }
nRowPosY += pRowInfo[nArrY].nHeight; nRowPosY += pRowInfo[nArrY].nHeight;
} }
delete pEngine;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */