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 @@
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::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8
}
}
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::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, sal_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, sal_False);
}
const EditTextObject* pRightArea(pPageItem->GetRightArea());
if (pRightArea)
{
aEditEngine.SetText(*pRightArea);
AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False);
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
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