Kaydet (Commit) e7168710 authored tarafından Armin Le Grand's avatar Armin Le Grand

#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
üst 803b94a2
...@@ -45,11 +45,15 @@ ...@@ -45,11 +45,15 @@
class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool 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); void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults);
public:
public:
ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport ); ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport );
virtual ~ScXMLFontAutoStylePool_Impl();
}; };
void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults) void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults)
...@@ -81,9 +85,9 @@ void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 ...@@ -81,9 +85,9 @@ void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8
} }
} }
ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl( ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP )
ScXMLExport& rExportP ) : : XMLFontAutoStylePool(rExportP),
XMLFontAutoStylePool( rExportP ) mpEditEnginePool(NULL)
{ {
sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT, sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
ATTR_CTL_FONT }; ATTR_CTL_FONT };
...@@ -107,11 +111,18 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl( ...@@ -107,11 +111,18 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
if(pItr) if(pItr)
{ {
SfxStyleSheetBase* pStyle(pItr->First()); SfxStyleSheetBase* pStyle(pItr->First());
SfxItemPool* pPageEditPool(EditEngine::CreatePool());
EditEngine aEditEngine(pPageEditPool); 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) while (pStyle)
{ {
const SfxItemPool& rPagePool(pStyle->GetPool().GetPool()); const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
for (sal_uInt8 j = 0; j < 4; ++j) for (sal_uInt8 j = 0; j < 4; ++j)
{ {
sal_uInt16 nPageWhichId(aPageWhichIds[j]); sal_uInt16 nPageWhichId(aPageWhichIds[j]);
...@@ -125,30 +136,42 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl( ...@@ -125,30 +136,42 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
if (pLeftArea) if (pLeftArea)
{ {
aEditEngine.SetText(*pLeftArea); aEditEngine.SetText(*pLeftArea);
AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False); AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
} }
const EditTextObject* pCenterArea(pPageItem->GetCenterArea()); const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
if (pCenterArea) if (pCenterArea)
{ {
aEditEngine.SetText(*pCenterArea); aEditEngine.SetText(*pCenterArea);
AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False); AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
} }
const EditTextObject* pRightArea(pPageItem->GetRightArea()); const EditTextObject* pRightArea(pPageItem->GetRightArea());
if (pRightArea) if (pRightArea)
{ {
aEditEngine.SetText(*pRightArea); aEditEngine.SetText(*pRightArea);
AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False); 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() XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
{ {
return new ScXMLFontAutoStylePool_Impl( *this ); return new ScXMLFontAutoStylePool_Impl( *this );
} }
// eof
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment