Kaydet (Commit) 30704655 authored tarafından Armin Le Grand's avatar Armin Le Grand Kaydeden (comit) Caolán McNamara

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 e7168710)

Conflicts:
	sc/source/filter/xml/xmlfonte.cxx

Change-Id: I75475bb59b3a7040938826d095dcd81e19d61b46
üst 752d005d
...@@ -32,11 +32,15 @@ ...@@ -32,11 +32,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, bool bBlockFontEmbedding ); 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) 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 ...@@ -66,9 +70,9 @@ void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8
} }
} }
ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl( ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, bool bBlockFontEmbedding)
ScXMLExport& rExportP, bool bBlockFontEmbedding ) : : XMLFontAutoStylePool(rExportP, bBlockFontEmbedding)
XMLFontAutoStylePool( rExportP, bBlockFontEmbedding ) , 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 };
...@@ -92,46 +96,63 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl( ...@@ -92,46 +96,63 @@ 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)
while (pStyle)
{ {
const SfxItemPool& rPagePool(pStyle->GetPool().GetPool()); // #i120077# remember the SfxItemPool in member variable before usage. The
for (sal_uInt8 j = 0; j < 4; ++j) // local EditEngine will not take over ownership of the pool.
mpEditEnginePool = EditEngine::CreatePool();
EditEngine aEditEngine(mpEditEnginePool);
while (pStyle)
{ {
sal_uInt16 nPageWhichId(aPageWhichIds[j]); const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
const ScPageHFItem* pPageItem; for (sal_uInt8 j = 0; j < 4; ++j)
for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
{ {
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 (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
if (pLeftArea)
{
aEditEngine.SetText(*pLeftArea);
AddFontItems(aEditWhichIds, 3, pPageEditPool, false);
}
const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
if (pCenterArea)
{ {
aEditEngine.SetText(*pCenterArea); const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
AddFontItems(aEditWhichIds, 3, pPageEditPool, false); if (pLeftArea)
} {
const EditTextObject* pRightArea(pPageItem->GetRightArea()); aEditEngine.SetText(*pLeftArea);
if (pRightArea) AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
{ }
aEditEngine.SetText(*pRightArea); const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
AddFontItems(aEditWhichIds, 3, pPageEditPool, false); 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() XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
{ {
......
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