You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by al...@apache.org on 2012/06/29 11:28:50 UTC
svn commit: r1355288 -
/incubator/ooo/trunk/main/sc/source/filter/xml/xmlfonte.cxx
Author: alg
Date: Fri Jun 29 09:28:49 2012
New Revision: 1355288
URL: http://svn.apache.org/viewvc?rev=1355288&view=rev
Log:
#120077# Added local var for SfxItemPool for EditEngine to avoid memory leak.
Found by: Chao Huang
Patch by: Chao Huang, alg
Review by: Chao Huang, alg
Modified:
incubator/ooo/trunk/main/sc/source/filter/xml/xmlfonte.cxx
Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlfonte.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlfonte.cxx?rev=1355288&r1=1355287&r2=1355288&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlfonte.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlfonte.cxx Fri Jun 29 09:28:49 2012
@@ -45,11 +45,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 );
-
+ virtual ~ScXMLFontAutoStylePool_Impl();
};
void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults)
@@ -81,9 +85,9 @@ void ScXMLFontAutoStylePool_Impl::AddFon
}
}
-ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
- ScXMLExport& rExportP ) :
- XMLFontAutoStylePool( rExportP )
+ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP )
+: XMLFontAutoStylePool(rExportP),
+ mpEditEnginePool(NULL)
{
sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
ATTR_CTL_FONT };
@@ -107,48 +111,67 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAu
if(pItr)
{
SfxStyleSheetBase* pStyle(pItr->First());
- SfxItemPool* pPageEditPool(EditEngine::CreatePool());
- EditEngine aEditEngine(pPageEditPool);
- while (pStyle)
- {
- const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
- for (sal_uInt8 j = 0; j < 4; ++j)
- {
- sal_uInt16 nPageWhichId(aPageWhichIds[j]);
- sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
- const ScPageHFItem* pPageItem;
- for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
- {
- if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
- {
- const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
- if (pLeftArea)
- {
- aEditEngine.SetText(*pLeftArea);
- AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False);
- }
- const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
- if (pCenterArea)
- {
- aEditEngine.SetText(*pCenterArea);
- AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False);
- }
- const EditTextObject* pRightArea(pPageItem->GetRightArea());
- if (pRightArea)
- {
- aEditEngine.SetText(*pRightArea);
- AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False);
- }
+
+ if(pStyle)
+ {
+ // #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)
+ {
+ const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
+
+ for (sal_uInt8 j = 0; j < 4; ++j)
+ {
+ sal_uInt16 nPageWhichId(aPageWhichIds[j]);
+ sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
+ const ScPageHFItem* pPageItem;
+ for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
+ {
+ if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
+ {
+ const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
+ if (pLeftArea)
+ {
+ aEditEngine.SetText(*pLeftArea);
+ AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
+ }
+ const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
+ if (pCenterArea)
+ {
+ aEditEngine.SetText(*pCenterArea);
+ AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
+ }
+ const EditTextObject* pRightArea(pPageItem->GetRightArea());
+ if (pRightArea)
+ {
+ aEditEngine.SetText(*pRightArea);
+ AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
+ }
+ }
}
}
+
+ pStyle = pItr->Next();
}
- pStyle = pItr->Next();
}
}
}
+ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
+{
+ if(mpEditEnginePool)
+ {
+ // memory leak #i120077#
+ SfxItemPool::Free(mpEditEnginePool);
+ }
+}
XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
{
return new ScXMLFontAutoStylePool_Impl( *this );
}
+
+// eof