[Libreoffice-commits] core.git: sc/source sfx2/source svl/inc svl/source sw/inc sw/source

Armin Le Grand alg at apache.org
Wed Apr 10 12:17:55 PDT 2013


 sc/source/core/data/patattr.cxx     |    5 ++---
 sc/source/core/data/stlsheet.cxx    |    2 +-
 sc/source/filter/xml/xmlfonte.cxx   |    8 +++++++-
 sfx2/source/doc/objcont.cxx         |    2 --
 svl/inc/svl/style.hxx               |    5 +++--
 svl/source/items/style.cxx          |   20 ++++++++------------
 sw/inc/docstyle.hxx                 |    3 +--
 sw/source/core/unocore/unostyle.cxx |    3 +--
 sw/source/ui/app/docstyle.cxx       |    5 ++---
 9 files changed, 25 insertions(+), 28 deletions(-)

New commits:
commit 858c6610f3476bb47bb7b4e621a7ac48a9e34a75
Author: Armin Le Grand <alg at apache.org>
Date:   Tue Jun 26 12:36:31 2012 +0000

    Resolves: #i120077# Memory leak fixed in ScXMLFontAutoStylePool_Impl
    
    also checked and fixed memory leaks caused by not deleting
    SfxStyleSheetIterator instances.
    
    Found by: Chao Huang
    Patch by: Chao Huang
    Review by: alg
    
    (cherry picked from commit aee8221b3fbe64d8e88aa3a1b630214807cd86f0)
    
    Conflicts:
    	sc/source/core/data/stlsheet.cxx
    	sc/source/filter/xml/xmlfonte.cxx
    	sfx2/source/doc/objcont.cxx
    	svl/source/items/style.cxx
    	sw/source/core/unocore/unostyle.cxx
    
    Resolves: #120077# ALG: Reverted r1354011,
    
    adapted all usages of SfxStyleSheetIterator and CreateIterator to use
    boost::shared_ptr
    
    (cherry picked from commit ec1819f218b94bed1556653e1b2b816a65da61ef)
    
    Conflicts:
    	sc/source/core/data/stlsheet.cxx
    	sc/source/filter/xml/xmlfonte.cxx
    	sfx2/source/doc/objcont.cxx
    	svl/inc/svl/style.hxx
    	svl/source/items/style.cxx
    	sw/source/core/unocore/unoframe.cxx
    	sw/source/core/unocore/unostyle.cxx
    
    26937d4d65562b14de0aea59a7b01cc4334f73c1
    
    Change-Id: If99bf3ee399292ec269d68b36ee78ed63f033215

diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index a391ad1..af1d5c9 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -1161,9 +1161,8 @@ void ScPatternAttr::UpdateStyleSheet()
         //! es wird vorausgesetzt, dass "Standard" immer der erste Eintrag ist!
         if (!pStyle)
         {
-            SfxStyleSheetIterator* pIter = pDoc->GetStyleSheetPool()->CreateIterator(
-                                                    SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
-            pStyle = (ScStyleSheet*)pIter->First();
+            SfxStyleSheetIteratorPtr pIter = pDoc->GetStyleSheetPool()->CreateIterator( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
+            pStyle = dynamic_cast< ScStyleSheet* >(pIter->First());
         }
 
         if (pStyle)
diff --git a/sc/source/core/data/stlsheet.cxx b/sc/source/core/data/stlsheet.cxx
index 3ef1b42b..eaa692a 100644
--- a/sc/source/core/data/stlsheet.cxx
+++ b/sc/source/core/data/stlsheet.cxx
@@ -109,7 +109,7 @@ bool ScStyleSheet::SetParent( const String& rParentName )
     SfxStyleSheetBase* pStyle = pPool->Find( aEffName, nFamily );
     if (!pStyle)
     {
-        SfxStyleSheetIterator* pIter = pPool->CreateIterator( nFamily, SFXSTYLEBIT_ALL );
+        SfxStyleSheetIteratorPtr pIter = pPool->CreateIterator( nFamily, SFXSTYLEBIT_ALL );
         pStyle = pIter->First();
         if (pStyle)
             aEffName = pStyle->GetName();
diff --git a/sc/source/filter/xml/xmlfonte.cxx b/sc/source/filter/xml/xmlfonte.cxx
index 4092bfa..9b0c263 100644
--- a/sc/source/filter/xml/xmlfonte.cxx
+++ b/sc/source/filter/xml/xmlfonte.cxx
@@ -82,7 +82,13 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
     const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
     AddFontItems(aEditWhichIds, 3, pEditPool, false);
 
-    SfxStyleSheetIterator* pItr(rExportP.GetDocument() ? rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF) : NULL);
+    SfxStyleSheetIteratorPtr pItr;
+
+    if(rExportP.GetDocument())
+    {
+        pItr = rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF);
+    }
+
     if(pItr)
     {
         SfxStyleSheetBase* pStyle(pItr->First());
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
index a03879c..7f3a31e 100644
--- a/sfx2/source/doc/objcont.cxx
+++ b/sfx2/source/doc/objcont.cxx
@@ -600,8 +600,6 @@ sal_Bool SfxObjectShell::Remove
     return bRet;
 }
 
-//--------------------------------------------------------------------
-
 void SfxObjectShell::LoadStyles
 (
     SfxObjectShell &rSource         /*  the document template from which
diff --git a/svl/inc/svl/style.hxx b/svl/inc/svl/style.hxx
index 664ca5c..af58cbc 100644
--- a/svl/inc/svl/style.hxx
+++ b/svl/inc/svl/style.hxx
@@ -37,10 +37,10 @@
 #include <svl/stylesheetuser.hxx>
 
 #include <svl/style.hrc>
+#include <boost/shared_ptr.hpp>
 
 class SfxItemSet;
 class SfxItemPool;
-
 class SfxStyleSheetBasePool;
 class SvStream;
 
@@ -192,6 +192,7 @@ private:
 friend class SfxStyleSheetBasePool;
 };
 
+typedef ::boost::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
 //=========================================================================
 
 class SfxStyleSheetBasePool_Impl;
@@ -228,7 +229,7 @@ public:
     SfxItemPool&                GetPool();
     const SfxItemPool&          GetPool() const;
 
-    virtual SfxStyleSheetIterator* CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
+    virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
     virtual sal_uInt16              Count();
     virtual SfxStyleSheetBase*  operator[](sal_uInt16 nIdx);
 
diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx
index cd44bea..c2879e7 100644
--- a/svl/source/items/style.cxx
+++ b/svl/source/items/style.cxx
@@ -83,10 +83,8 @@ SfxStyleSheetHint::SfxStyleSheetHint
 
 class SfxStyleSheetBasePool_Impl
 {
-  public:
-    SfxStyleSheetIterator *pIter;
-    SfxStyleSheetBasePool_Impl() : pIter(0){}
-    ~SfxStyleSheetBasePool_Impl(){delete pIter;}
+public:
+    SfxStyleSheetIteratorPtr pIter;
 };
 
 
@@ -532,13 +530,12 @@ void SfxStyleSheetBasePool::Replace(
 
 SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl()
 {
-    SfxStyleSheetIterator*& rpIter = pImp->pIter;
-    if( !rpIter || (rpIter->GetSearchMask() != nMask) || (rpIter->GetSearchFamily() != nSearchFamily) )
+    if( !pImp->pIter || (pImp->pIter->GetSearchMask() != nMask) || (pImp->pIter->GetSearchFamily() != nSearchFamily) )
     {
-        delete rpIter;
-        rpIter = CreateIterator( nSearchFamily, nMask );
+        pImp->pIter = CreateIterator( nSearchFamily, nMask );
     }
-    return *rpIter;
+
+    return *pImp->pIter;
 }
 
 SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool& r )
@@ -603,14 +600,13 @@ sal_uInt16 SfxStyleSheetBasePool::GetSearchMask() const
     return nMask;
 }
 
-
-SfxStyleSheetIterator* SfxStyleSheetBasePool::CreateIterator
+SfxStyleSheetIteratorPtr SfxStyleSheetBasePool::CreateIterator
 (
  SfxStyleFamily eFam,
  sal_uInt16 mask
 )
 {
-    return new SfxStyleSheetIterator(this,eFam,mask);
+    return SfxStyleSheetIteratorPtr(new SfxStyleSheetIterator(this,eFam,mask));
 }
 
 SfxStyleSheetBase* SfxStyleSheetBasePool::Create
diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx
index 72ea158..90a049e 100644
--- a/sw/inc/docstyle.hxx
+++ b/sw/inc/docstyle.hxx
@@ -208,8 +208,7 @@ public:
     void    SetOrganizerMode( sal_Bool bMode )  { bOrganizer = bMode; }
     sal_Bool    IsOrganizerMode() const         { return bOrganizer; }
 
-    virtual SfxStyleSheetIterator* CreateIterator( SfxStyleFamily,
-                                                    sal_uInt16 nMask );
+    virtual SfxStyleSheetIteratorPtr CreateIterator( SfxStyleFamily, sal_uInt16 nMask );
 
     SwDoc& GetDoc() const { return rDoc; }
 
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 49502e0..a7d3b17 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -785,7 +785,7 @@ uno::Sequence< OUString > SwXStyleFamily::getElementNames(void) throw( uno::Runt
     uno::Sequence< OUString > aRet;
     if(pBasePool)
     {
-        SfxStyleSheetIterator* pIterator = pBasePool->CreateIterator(eFamily, SFXSTYLEBIT_ALL);
+        SfxStyleSheetIteratorPtr pIterator = pBasePool->CreateIterator(eFamily, SFXSTYLEBIT_ALL);
         sal_uInt16 nCount = pIterator->Count();
         aRet.realloc(nCount);
         OUString* pArray = aRet.getArray();
@@ -795,7 +795,6 @@ uno::Sequence< OUString > SwXStyleFamily::getElementNames(void) throw( uno::Runt
             SwStyleNameMapper::FillProgName((*pIterator)[i]->GetName(), aString, lcl_GetSwEnumFromSfxEnum ( eFamily ), true );
             pArray[i] = OUString ( aString );
         }
-        delete pIterator;
     }
     else
         throw uno::RuntimeException();
diff --git a/sw/source/ui/app/docstyle.cxx b/sw/source/ui/app/docstyle.cxx
index 2af3322..934f717 100644
--- a/sw/source/ui/app/docstyle.cxx
+++ b/sw/source/ui/app/docstyle.cxx
@@ -2179,10 +2179,9 @@ void  SwDocStyleSheetPool::Replace( SfxStyleSheetBase& rSource,
     }
 }
 
-SfxStyleSheetIterator*  SwDocStyleSheetPool::CreateIterator(
-                        SfxStyleFamily eFam, sal_uInt16 _nMask )
+SfxStyleSheetIteratorPtr SwDocStyleSheetPool::CreateIterator( SfxStyleFamily eFam, sal_uInt16 _nMask )
 {
-    return new SwStyleSheetIterator( this, eFam, _nMask );
+    return SfxStyleSheetIteratorPtr(new SwStyleSheetIterator( this, eFam, _nMask ));
 }
 
 void SwDocStyleSheetPool::dispose()


More information about the Libreoffice-commits mailing list