diff options
author | Armin Le Grand <alg@apache.org> | 2012-06-29 08:04:31 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-04-13 10:17:53 +0100 |
commit | 5c012ae5ebb21c65f2f854e55eff2dd637c2f8c8 (patch) | |
tree | eb4fe2daa0f786ece2c4fda11d1eaca9517d6787 /sc/source/ui/unoobj | |
parent | 336e04496fa06cef99351692d60b2618c969d787 (diff) |
Resolves: #i120105# Avoid MemoryLeak in ScTableSheetObj::PrintAreaUndo_Impl
by handling created ScPrintRageSaver objects more careful.
Found by: Chao Huang
Patch by: Chao Huang, alg
Review by: alg(cherry picked from commit 803b94a2391352ccef46a6f8fdcfa9dc748bb737)
Change-Id: I0523bb870ed6a4ee301722e6e80dc9ac497a7299
Diffstat (limited to 'sc/source/ui/unoobj')
-rw-r--r-- | sc/source/ui/unoobj/cellsuno.cxx | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 2d4a3bfa4ca1..067e3f4b50cd 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -7435,31 +7435,40 @@ void SAL_CALL ScTableSheetObj::copyRange( const table::CellAddress& aDestination void ScTableSheetObj::PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges ) { // Umbrueche und Undo - ScDocShell* pDocSh = GetDocShell(); - if ( pDocSh ) + ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : 0; + + if(pDocSh && pDoc) { - ScDocument* pDoc = pDocSh->GetDocument(); - sal_Bool bUndo(pDoc->IsUndoEnabled()); - SCTAB nTab = GetTab_Impl(); + const bool bUndo(pDoc->IsUndoEnabled()); + const SCTAB nTab(GetTab_Impl()); - ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver(); - if (bUndo) + if(bUndo) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoPrintRange( pDocSh, nTab, pOldRanges, pNewRanges ) ); - } + new ScUndoPrintRange( + pDocSh, + nTab, + pOldRanges, + pDoc->CreatePrintRangeSaver())); // create new ranges - ScPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ).UpdatePages(); + // #i120105# ownership of old ranges has changed, mark as consumed + pOldRanges = 0; + } + ScPrintFunc(pDocSh, pDocSh->GetPrinter(), nTab).UpdatePages(); SfxBindings* pBindings = pDocSh->GetViewBindings(); - if (pBindings) - pBindings->Invalidate( SID_DELETE_PRINTAREA ); + + if(pBindings) + { + pBindings->Invalidate(SID_DELETE_PRINTAREA); + } pDocSh->SetDocumentModified(); } - else - delete pOldRanges; + + // #i120105# pOldRanges not used, need to cleanup + delete pOldRanges; } uno::Sequence<table::CellRangeAddress> SAL_CALL ScTableSheetObj::getPrintAreas() |