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

Armin Le Grand alg at apache.org
Thu Apr 11 01:35:34 PDT 2013


 sc/source/filter/xml/xmlfonte.cxx |   85 +++++++++++++++++++++++---------------
 1 file changed, 53 insertions(+), 32 deletions(-)

New commits:
commit 30704655570ea2b4c6943e18de02497284b2174c
Author: Armin Le Grand <alg at apache.org>
Date:   Fri Jun 29 08:28:49 2012 +0000

    Related: #i120077# Added local var for SfxItemPool for EditEngine
    
    to avoid a memory leak.
    
    Found by: Chao Huang
    Patch by: Chao Huang, alg
    Review by: Chao Huang, alg
    
    (cherry picked from commit e7168710bfd30b5d682d21d81c116cd33cf22505)
    
    Conflicts:
    	sc/source/filter/xml/xmlfonte.cxx
    
    Change-Id: I75475bb59b3a7040938826d095dcd81e19d61b46

diff --git a/sc/source/filter/xml/xmlfonte.cxx b/sc/source/filter/xml/xmlfonte.cxx
index 9b0c263..50296ba 100644
--- a/sc/source/filter/xml/xmlfonte.cxx
+++ b/sc/source/filter/xml/xmlfonte.cxx
@@ -32,11 +32,15 @@
 
 class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
 {
+private:
+    // #i120077# remember owned pool
+    SfxItemPool*    mpEditEnginePool;
+
     void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults);
-    public:
 
+public:
     ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport, bool bBlockFontEmbedding );
-
+    virtual ~ScXMLFontAutoStylePool_Impl();
 };
 
 void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults)
@@ -66,9 +70,9 @@ void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8
     }
 }
 
-ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
-    ScXMLExport& rExportP, bool bBlockFontEmbedding ) :
-    XMLFontAutoStylePool( rExportP, bBlockFontEmbedding )
+ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, bool bBlockFontEmbedding)
+    : XMLFontAutoStylePool(rExportP, bBlockFontEmbedding)
+    , mpEditEnginePool(NULL)
 {
     sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
                                 ATTR_CTL_FONT };
@@ -92,46 +96,63 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
     if(pItr)
     {
         SfxStyleSheetBase* pStyle(pItr->First());
-        SfxItemPool* pPageEditPool(EditEngine::CreatePool());
-        EditEngine aEditEngine(pPageEditPool);
-        while (pStyle)
+
+        if(pStyle)
         {
-            const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
-            for (sal_uInt8 j = 0; j < 4; ++j)
+            // #i120077# remember the SfxItemPool in member variable before usage. The
+            // local EditEngine will not take over ownership of the pool.
+            mpEditEnginePool = EditEngine::CreatePool();
+            EditEngine aEditEngine(mpEditEnginePool);
+
+            while (pStyle)
             {
-                sal_uInt16 nPageWhichId(aPageWhichIds[j]);
-                sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
-                const ScPageHFItem* pPageItem;
-                for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
+                const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
+
+                for (sal_uInt8 j = 0; j < 4; ++j)
                 {
-                    if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
+                    sal_uInt16 nPageWhichId(aPageWhichIds[j]);
+                    sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
+                    const ScPageHFItem* pPageItem;
+                    for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
                     {
-                        const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
-                        if (pLeftArea)
-                        {
-                            aEditEngine.SetText(*pLeftArea);
-                            AddFontItems(aEditWhichIds, 3, pPageEditPool, false);
-                        }
-                        const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
-                        if (pCenterArea)
+                        if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
                         {
-                            aEditEngine.SetText(*pCenterArea);
-                            AddFontItems(aEditWhichIds, 3, pPageEditPool, false);
-                        }
-                        const EditTextObject* pRightArea(pPageItem->GetRightArea());
-                        if (pRightArea)
-                        {
-                            aEditEngine.SetText(*pRightArea);
-                            AddFontItems(aEditWhichIds, 3, pPageEditPool, false);
+                            const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
+                            if (pLeftArea)
+                            {
+                                aEditEngine.SetText(*pLeftArea);
+                                AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
+                            }
+                            const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
+                            if (pCenterArea)
+                            {
+                                aEditEngine.SetText(*pCenterArea);
+                                AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
+                            }
+                            const EditTextObject* pRightArea(pPageItem->GetRightArea());
+                            if (pRightArea)
+                            {
+                                aEditEngine.SetText(*pRightArea);
+                                AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
+                            }
                         }
                     }
                 }
+
+                pStyle = pItr->Next();
             }
-            pStyle = pItr->Next();
         }
     }
 }
 
+ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
+{
+    if(mpEditEnginePool)
+    {
+        // memory leak #i120077#
+        SfxItemPool::Free(mpEditEnginePool);
+    }
+}
 
 XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
 {


More information about the Libreoffice-commits mailing list