[Libreoffice-commits] core.git: sc/source

Armin Le Grand alg at apache.org
Sat Apr 13 02:19:30 PDT 2013


 sc/source/ui/unoobj/cellsuno.cxx |   37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

New commits:
commit 5c012ae5ebb21c65f2f854e55eff2dd637c2f8c8
Author: Armin Le Grand <alg at apache.org>
Date:   Fri Jun 29 08:04:31 2012 +0000

    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

diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 2d4a3bf..067e3f4 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()


More information about the Libreoffice-commits mailing list