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

#120077# Memory leak fixed in ScXMLFontAutoStylePool_Impl, also chekced and…

#120077# Memory leak fixed in ScXMLFontAutoStylePool_Impl, also chekced and fixed memory leaks caused by not deleting SfxStyleSheetIterator instances.

Found by: Chao Huang
Patch by: Chao Huang
Review by: alg
üst 79336603
......@@ -1187,16 +1187,17 @@ void ScPatternAttr::UpdateStyleSheet()
{
if (pName)
{
pStyle = (ScStyleSheet*)pDoc->GetStyleSheetPool()->Find(*pName, SFX_STYLE_FAMILY_PARA);
pStyle = dynamic_cast< ScStyleSheet* >(pDoc->GetStyleSheetPool()->Find(*pName, SFX_STYLE_FAMILY_PARA));
// wenn Style nicht gefunden, Standard nehmen,
// damit keine leere Anzeige im Toolbox-Controller
//! es wird vorausgesetzt, dass "Standard" immer der erste Eintrag ist!
if (!pStyle)
{
SfxStyleSheetIterator* pIter = pDoc->GetStyleSheetPool()->CreateIterator(
SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
pStyle = (ScStyleSheet*)pIter->First();
// #i120077# memory leak
SfxStyleSheetIterator aIter(pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
pStyle = dynamic_cast< ScStyleSheet* >(aIter.First());
}
if (pStyle)
......
......@@ -119,8 +119,11 @@ sal_Bool __EXPORT ScStyleSheet::SetParent( const String& rParentName )
SfxStyleSheetBase* pStyle = rPool.Find( aEffName, nFamily );
if (!pStyle)
{
SfxStyleSheetIterator* pIter = rPool.CreateIterator( nFamily, SFXSTYLEBIT_ALL );
pStyle = pIter->First();
// memory leak #i120077#
SfxStyleSheetIterator aIter(&rPool, nFamily, SFXSTYLEBIT_ALL);
pStyle = aIter.First();
if (pStyle)
aEffName = pStyle->GetName();
}
......
......@@ -45,11 +45,14 @@
class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
{
void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults);
public:
private:
// #i120077# remember owned pool
SfxItemPool* mpEditEnginePool;
void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults);
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)
......@@ -83,7 +86,8 @@ void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8
ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
ScXMLExport& rExportP ) :
XMLFontAutoStylePool( rExportP )
XMLFontAutoStylePool( rExportP ),
mpEditEnginePool(0)
{
sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
ATTR_CTL_FONT };
......@@ -97,12 +101,17 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
AddFontItems(aEditWhichIds, 3, pEditPool, sal_False);
SfxStyleSheetIterator* pItr(rExportP.GetDocument() ? rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF) : NULL);
if(pItr)
if(rExportP.GetDocument() && rExportP.GetDocument()->GetStyleSheetPool())
{
SfxStyleSheetBase* pStyle(pItr->First());
SfxItemPool* pPageEditPool(EditEngine::CreatePool());
// memory leak #i120077#
SfxStyleSheetIterator aIter(rExportP.GetDocument()->GetStyleSheetPool(), SFX_STYLE_FAMILY_PAGE, 0xFFFF);
SfxStyleSheetBase* pStyle(aIter.First());
// #i120077# init pool and use it
mpEditEnginePool = EditEngine::CreatePool(); // memory leak #i120077#, to save the SfxItemPool obj into member data for releasing
SfxItemPool* pPageEditPool( mpEditEnginePool );
EditEngine aEditEngine(pPageEditPool);
while (pStyle)
{
const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
......@@ -136,11 +145,19 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
}
}
}
pStyle = pItr->Next();
pStyle = aIter.Next();
}
}
}
ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
{
if(mpEditEnginePool)
{
// memory leak #i120077#
SfxItemPool::Free(mpEditEnginePool);
}
}
XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
{
......
......@@ -759,12 +759,16 @@ sal_Bool SfxObjectShell::Print
{
SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
SetOrganizerSearchMask(pStylePool);
SfxStyleSheetIterator* pIter = pStylePool->CreateIterator(
pStylePool->GetSearchFamily(), pStylePool->GetSearchMask() );
sal_uInt16 nStyles = pIter->Count();
SfxStyleSheetBase *pStyle = pIter->First();
// memory leak #i120077#
SfxStyleSheetIterator aIter(pStylePool, pStylePool->GetSearchFamily(), pStylePool->GetSearchMask());
sal_uInt16 nStyles = aIter.Count();
SfxStyleSheetBase *pStyle = aIter.First();
if ( !pStyle )
{
return sal_True;
}
// pepare adaptor for old style StartPage/EndPage printing
boost::shared_ptr< Printer > pPrinter( new Printer( rPrt.GetJobSetup() ) );
......@@ -863,13 +867,12 @@ sal_Bool SfxObjectShell::Print
pPrinter->DrawText(aOutPos, aTmp);
aOutPos.Y() += pPrinter->GetTextHeight();
}
pStyle = pIter->Next();
pStyle = aIter.Next();
}
pAdaptor->EndPage();
Printer::PrintJob( pController, rPrt.GetJobSetup() );
delete pIter;
break;
}
default:
......
......@@ -238,7 +238,6 @@ public:
SfxItemPool& GetPool();
const SfxItemPool& GetPool() const;
virtual SfxStyleSheetIterator* CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
virtual sal_uInt16 Count();
virtual SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
......
......@@ -587,7 +587,7 @@ SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl()
if( !rpIter || (rpIter->GetSearchMask() != nMask) || (rpIter->GetSearchFamily() != nSearchFamily) )
{
delete rpIter;
rpIter = CreateIterator( nSearchFamily, nMask );
rpIter = new SfxStyleSheetIterator( this, nSearchFamily, nMask );
}
return *rpIter;
}
......@@ -668,16 +668,6 @@ String SfxStyleSheetBasePool::GetStreamName()
SfxStyleSheetIterator* SfxStyleSheetBasePool::CreateIterator
(
SfxStyleFamily eFam,
sal_uInt16 mask
)
{
return new SfxStyleSheetIterator(this,eFam,mask);
}
SfxStyleSheetBase* SfxStyleSheetBasePool::Create
(
const XubString& rName,
......
......@@ -219,9 +219,6 @@ public:
void SetOrganizerMode( sal_Bool bMode ) { bOrganizer = bMode; }
sal_Bool IsOrganizerMode() const { return bOrganizer; }
virtual SfxStyleSheetIterator* CreateIterator( SfxStyleFamily,
sal_uInt16 nMask );
SwDoc& GetDoc() const { return rDoc; }
void dispose();
......
......@@ -860,17 +860,16 @@ uno::Sequence< OUString > SwXStyleFamily::getElementNames(void) throw( uno::Runt
uno::Sequence< OUString > aRet;
if(pBasePool)
{
SfxStyleSheetIterator* pIterator = pBasePool->CreateIterator(eFamily, 0xffff);
sal_uInt16 nCount = pIterator->Count();
SfxStyleSheetIterator aIterator(pBasePool, eFamily, 0xffff);
sal_uInt16 nCount = aIterator.Count();
aRet.realloc(nCount);
OUString* pArray = aRet.getArray();
String aString;
for(sal_uInt16 i = 0; i < nCount; i++)
{
SwStyleNameMapper::FillProgName((*pIterator)[i]->GetName(), aString, lcl_GetSwEnumFromSfxEnum ( eFamily ), sal_True );
SwStyleNameMapper::FillProgName(aIterator[i]->GetName(), aString, lcl_GetSwEnumFromSfxEnum ( eFamily ), sal_True );
pArray[i] = OUString ( aString );
}
delete pIterator;
}
else
throw uno::RuntimeException();
......
......@@ -2230,12 +2230,6 @@ void SwDocStyleSheetPool::Replace( SfxStyleSheetBase& rSource,
}
}
SfxStyleSheetIterator* SwDocStyleSheetPool::CreateIterator(
SfxStyleFamily eFam, sal_uInt16 _nMask )
{
return new SwStyleSheetIterator( this, eFam, _nMask );
}
void SwDocStyleSheetPool::dispose()
{
mxStyleSheet.clear();
......
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