From 608a67ac73a14a563c5f7692d4ca5de28777f290 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 11 Jun 2014 17:46:53 +0200 Subject: Fix memory leaks, by refcounting XFContent Change-Id: I8c94c63230eec13bf22043ff07f9f480a0463111 --- lotuswordpro/source/filter/lwpfribframe.cxx | 4 ++- lotuswordpro/source/filter/lwpfribtable.cxx | 4 ++- lotuswordpro/source/filter/lwpgrfobj.cxx | 10 +++---- lotuswordpro/source/filter/lwpgrfobj.hxx | 2 +- lotuswordpro/source/filter/lwpsdwfileloader.cxx | 2 +- lotuswordpro/source/filter/lwpsdwfileloader.hxx | 10 +++++-- .../source/filter/lwpsdwgrouploaderv0102.cxx | 2 +- .../source/filter/lwpsdwgrouploaderv0102.hxx | 9 ++++-- lotuswordpro/source/filter/lwpstory.cxx | 8 ++++-- lotuswordpro/source/filter/lwptablelayout.cxx | 5 ++-- lotuswordpro/source/filter/xfilter/xfcontent.hxx | 7 +++-- .../source/filter/xfilter/xfcontentcontainer.cxx | 33 ++++++---------------- .../source/filter/xfilter/xfcontentcontainer.hxx | 14 ++++----- lotuswordpro/source/filter/xfilter/xfframe.cxx | 6 ++-- lotuswordpro/source/filter/xfilter/xftextspan.cxx | 22 ++++----------- lotuswordpro/source/filter/xfilter/xftextspan.hxx | 9 ++++-- 16 files changed, 72 insertions(+), 75 deletions(-) (limited to 'lotuswordpro') diff --git a/lotuswordpro/source/filter/lwpfribframe.cxx b/lotuswordpro/source/filter/lwpfribframe.cxx index 5d5c20c13ecb..fbf4cf29ba7e 100644 --- a/lotuswordpro/source/filter/lwpfribframe.cxx +++ b/lotuswordpro/source/filter/lwpfribframe.cxx @@ -165,7 +165,9 @@ void LwpFribFrame::XFConvert(XFContentContainer* pCont) else if(pContainerLayout && pContainerLayout->IsCell()) { //same page as text and in cell, get the first xfpara - XFContentContainer* pXFFirtPara = static_cast(pCont->FindFirstContent(enumXFContentPara)); + rtl::Reference first( + pCont->FindFirstContent(enumXFContentPara)); + XFContentContainer* pXFFirtPara = static_cast(first.get()); if(pXFFirtPara) pXFContentContainer = pXFFirtPara; } diff --git a/lotuswordpro/source/filter/lwpfribtable.cxx b/lotuswordpro/source/filter/lwpfribtable.cxx index 21f7b8150aa1..8c722fc82f1d 100644 --- a/lotuswordpro/source/filter/lwpfribtable.cxx +++ b/lotuswordpro/source/filter/lwpfribtable.cxx @@ -127,7 +127,9 @@ void LwpFribTable::XFConvert(XFContentContainer* pCont) else if(pContainer->IsCell()) { //same page as text and in cell, get the first xfpara - XFContentContainer* pXFFirtPara = static_cast(pCont->FindFirstContent(enumXFContentPara)); + rtl::Reference first( + pCont->FindFirstContent(enumXFContentPara)); + XFContentContainer* pXFFirtPara = static_cast(first.get()); if(pXFFirtPara) pXFContentContainer = pXFFirtPara; } diff --git a/lotuswordpro/source/filter/lwpgrfobj.cxx b/lotuswordpro/source/filter/lwpgrfobj.cxx index 6e884626aaf7..7ec84d640ec5 100644 --- a/lotuswordpro/source/filter/lwpgrfobj.cxx +++ b/lotuswordpro/source/filter/lwpgrfobj.cxx @@ -197,15 +197,15 @@ void LwpGraphicObject::XFConvert (XFContentContainer* pCont) { if ((m_sServerContextFormat[1]=='s'&&m_sServerContextFormat[2]=='d'&&m_sServerContextFormat[3]=='w')) { - std::vector ::iterator iter; + std::vector< rtl::Reference >::iterator iter; for (iter = m_vXFDrawObjects.begin(); iter != m_vXFDrawObjects.end(); ++iter) { - pCont->Add(*iter); + pCont->Add(iter->get()); } } else if (this->IsGrafFormatValid()) { - XFImage* pImage = static_cast(m_vXFDrawObjects.front()); + XFImage* pImage = static_cast(m_vXFDrawObjects.front().get()); if (m_bIsLinked) { @@ -438,7 +438,7 @@ sal_uInt32 LwpGraphicObject::GetGrafData(sal_uInt8*& pGrafData) */ void LwpGraphicObject::CreateGrafObject() { - XFImage* pImage = new XFImage(); + rtl::Reference pImage = new XFImage(); // set image processing styles XFImageStyle* pImageStyle = new XFImageStyle(); @@ -660,7 +660,7 @@ void LwpGraphicObject::CreateGrafObject() } // insert image object into array - m_vXFDrawObjects.push_back(pImage); + m_vXFDrawObjects.push_back(pImage.get()); } diff --git a/lotuswordpro/source/filter/lwpgrfobj.hxx b/lotuswordpro/source/filter/lwpgrfobj.hxx index a2043c10c381..18a2e23ace21 100644 --- a/lotuswordpro/source/filter/lwpgrfobj.hxx +++ b/lotuswordpro/source/filter/lwpgrfobj.hxx @@ -110,7 +110,7 @@ private: void ParseChart(IXFStream* pOutputStream); bool IsGrafFormatValid(); // add by , 03/25/2005 - std::vector m_vXFDrawObjects; + std::vector< rtl::Reference > m_vXFDrawObjects; // end add public: diff --git a/lotuswordpro/source/filter/lwpsdwfileloader.cxx b/lotuswordpro/source/filter/lwpsdwfileloader.cxx index e34ec7967468..3c3ed764fec4 100644 --- a/lotuswordpro/source/filter/lwpsdwfileloader.cxx +++ b/lotuswordpro/source/filter/lwpsdwfileloader.cxx @@ -78,7 +78,7 @@ LwpSdwFileLoader::~LwpSdwFileLoader(void) * @descr entry of lwp-drawing objects. * @param pDrawObjVector a container which will contains the created drawing object of XF-Model. */ -void LwpSdwFileLoader::CreateDrawObjects(std::vector * pDrawObjVector) +void LwpSdwFileLoader::CreateDrawObjects(std::vector< rtl::Reference >* pDrawObjVector) { unsigned char BinSignature[2]; m_pStream->Read(BinSignature,2); diff --git a/lotuswordpro/source/filter/lwpsdwfileloader.hxx b/lotuswordpro/source/filter/lwpsdwfileloader.hxx index 3d6e52c9c501..a634eda1a34e 100644 --- a/lotuswordpro/source/filter/lwpsdwfileloader.hxx +++ b/lotuswordpro/source/filter/lwpsdwfileloader.hxx @@ -62,11 +62,15 @@ #ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_LWPSDWFILELOADER_HXX #define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_LWPSDWFILELOADER_HXX -#include +#include + +#include + +#include #include + #include "lwpheader.hxx" #include "xfilter/ixfstream.hxx" -#include class XFFrame; class LwpGraphicObject; @@ -83,7 +87,7 @@ public: // void RegisterStyle(void); // add by ,03/25/2005 - void CreateDrawObjects(std::vector * pDrawObjVector); + void CreateDrawObjects(std::vector< rtl::Reference >* pDrawObjVector); // end add }; diff --git a/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.cxx b/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.cxx index 83459025bc3d..430de02ad88e 100644 --- a/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.cxx +++ b/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.cxx @@ -93,7 +93,7 @@ LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102() * the corresponding drawing objects. * @param pDrawObjVector a container which will contains the created drawing object of XF-Model. */ -void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector * pDrawObjVector) +void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector< rtl::Reference >* pDrawObjVector) { // save the container m_pDrawObjVector = pDrawObjVector; diff --git a/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.hxx b/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.hxx index 5611ae8634c4..f8d8d7b017ab 100644 --- a/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.hxx +++ b/lotuswordpro/source/filter/lwpsdwgrouploaderv0102.hxx @@ -62,9 +62,12 @@ #ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_LWPSDWGROUPLOADERV0102_HXX #define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_LWPSDWGROUPLOADERV0102_HXX +#include + +#include #include + #include "lwpheader.hxx" -#include "assert.h" #include "lwpsdwdrawheader.hxx" class XFFrame; @@ -75,7 +78,7 @@ class LwpSdwGroupLoaderV0102 private: SvStream* m_pStream; LwpGraphicObject* m_pGraphicObj; - std::vector * m_pDrawObjVector; + std::vector< rtl::Reference >* m_pDrawObjVector; DrawingOffsetAndScale m_aTransformData; @@ -84,7 +87,7 @@ public: ~LwpSdwGroupLoaderV0102(); public: - void BeginDrawObjects(std::vector * pDrawObjVector); + void BeginDrawObjects(std::vector< rtl::Reference >* pDrawObjVector); XFDrawGroup* CreateDrawGroupObject(void); XFFrame* CreateDrawObject(void); // end add diff --git a/lotuswordpro/source/filter/lwpstory.cxx b/lotuswordpro/source/filter/lwpstory.cxx index c7875b5fdda5..e38197a5b8b0 100644 --- a/lotuswordpro/source/filter/lwpstory.cxx +++ b/lotuswordpro/source/filter/lwpstory.cxx @@ -348,7 +348,9 @@ void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont) if(pFrameLayout->IsAnchorCell() && pFrameLayout->HasContent()) { //get the first xfpara - XFContentContainer* pXFFirtPara = static_cast(pCont->FindFirstContent(enumXFContentPara)); + rtl::Reference first( + pCont->FindFirstContent(enumXFContentPara)); + XFContentContainer* pXFFirtPara = static_cast(first.get()); if(pXFFirtPara) pFrameLayout->XFConvert(pXFFirtPara); } @@ -424,7 +426,9 @@ void LwpStory::XFConvertFrameInHeaderFooter(XFContentContainer* pCont) if(pFrameLayout->IsAnchorPage() && (pLayout->IsHeader() || pLayout->IsFooter())) { //The frame must be included by - XFContentContainer* pXFFirtPara = static_cast(pCont->FindFirstContent(enumXFContentPara)); + rtl::Reference first( + pCont->FindFirstContent(enumXFContentPara)); + XFContentContainer* pXFFirtPara = static_cast(first.get()); if(pXFFirtPara) pFrameLayout->XFConvert(pXFFirtPara); } diff --git a/lotuswordpro/source/filter/lwptablelayout.cxx b/lotuswordpro/source/filter/lwptablelayout.cxx index dd47ba034ba3..1a018a4edc47 100644 --- a/lotuswordpro/source/filter/lwptablelayout.cxx +++ b/lotuswordpro/source/filter/lwptablelayout.cxx @@ -1183,8 +1183,9 @@ void LwpTableLayout::PostProcessParagraph(XFCell *pCell, sal_uInt16 nRowID, sal_ LwpCellLayout * pCellLayout = GetCellByRowCol(nRowID, nColID); if(pCellLayout) { - XFParagraph * pXFPara = NULL; - pXFPara = static_cast(pCell->FindFirstContent(enumXFContentPara)); + rtl::Reference first( + pCell->FindFirstContent(enumXFContentPara)); + XFParagraph * pXFPara = static_cast(first.get()); if (!pXFPara) return; XFColor aNullColor = XFColor(); diff --git a/lotuswordpro/source/filter/xfilter/xfcontent.hxx b/lotuswordpro/source/filter/xfilter/xfcontent.hxx index 04622723df1d..2d1dfa7e7b15 100644 --- a/lotuswordpro/source/filter/xfilter/xfcontent.hxx +++ b/lotuswordpro/source/filter/xfilter/xfcontent.hxx @@ -63,6 +63,7 @@ #include #include +#include #include "xfdefs.hxx" @@ -73,11 +74,9 @@ class IXFStream; * Base class for all content object. * There is only two properties:style name and content type in this class. */ -class XFContent +class XFContent: public salhelper::SimpleReferenceObject { public: - virtual ~XFContent() {} - /** * @short: return the content type. */ @@ -98,6 +97,8 @@ public: protected: XFContent() {} + virtual ~XFContent() {} + OUString m_strStyleName; }; diff --git a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx index d3774c5471a1..a4a0c891b89b 100644 --- a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx +++ b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx @@ -66,13 +66,6 @@ XFContentContainer::XFContentContainer() XFContentContainer::~XFContentContainer() { - std::vector::iterator it; - - for( it = m_aContents.begin(); it != m_aContents.end(); ++it ) - { - XFContent *pContent = *it; - delete pContent; - } } void XFContentContainer::Add(XFContent *pContent) @@ -102,26 +95,18 @@ int XFContentContainer::GetCount() const void XFContentContainer::Reset() { - std::vector::iterator it; - - for( it = m_aContents.begin(); it != m_aContents.end(); ++it ) - { - XFContent *pContent = *it; - if( pContent ) - delete pContent; - } m_aContents.clear(); } -XFContent* XFContentContainer::FindFirstContent(enumXFContent type) +rtl::Reference XFContentContainer::FindFirstContent(enumXFContent type) { - XFContent *pRet = NULL; - XFContent *pContent = NULL; + rtl::Reference pRet; + rtl::Reference pContent; for( int i=0; iGetContentType(); @@ -129,11 +114,11 @@ XFContent* XFContentContainer::FindFirstContent(enumXFContent type) return pContent; else { - XFContentContainer *pChildCont = static_cast(pContent); + XFContentContainer *pChildCont = static_cast(pContent.get()); if( pChildCont ) { pRet = pChildCont->FindFirstContent(type); - if( pRet ) + if( pRet.is() ) return pRet; } } @@ -148,17 +133,17 @@ enumXFContent XFContentContainer::GetContentType() void XFContentContainer::ToXml(IXFStream *pStrm) { - std::vector::iterator it; + std::vector< rtl::Reference >::iterator it; for( it = m_aContents.begin(); it != m_aContents.end(); ++it ) { - XFContent *pContent = *it; + XFContent *pContent = it->get(); if( pContent ) pContent->ToXml(pStrm); } } -XFContent* XFContentContainer::GetLastContent() +rtl::Reference XFContentContainer::GetLastContent() { sal_uInt32 index = m_aContents.size()-1; if(index >0) diff --git a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.hxx b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.hxx index 7b0648d0f13f..c05c9d7e46fa 100644 --- a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.hxx +++ b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.hxx @@ -64,7 +64,7 @@ #include -#include +#include #include "xfcontent.hxx" @@ -73,7 +73,7 @@ * A container for content. * The contents will be deleted when delete container. */ -class XFContentContainer : public XFContent, private boost::noncopyable +class XFContentContainer : public XFContent { public: XFContentContainer(); @@ -91,7 +91,7 @@ public: virtual void InsertAtBegin(XFContent *pContent); virtual void RemoveAt(sal_uInt32 nPos); - virtual XFContent* GetLastContent(); + virtual rtl::Reference GetLastContent(); virtual void RemoveLastContent(); /** * @descr convience function for add text content. @@ -106,7 +106,7 @@ public: /** * @descr get content by index. */ - XFContent* GetContent(sal_uInt32 index) const; + rtl::Reference GetContent(sal_uInt32 index) const; /** * @descr clear all contents in the container. @@ -116,7 +116,7 @@ public: /** * @descr helper function, find first content by type. */ - XFContent* FindFirstContent(enumXFContent type); + rtl::Reference FindFirstContent(enumXFContent type); /** * @descr return the content type. @@ -128,10 +128,10 @@ public: virtual void ToXml(IXFStream *pStrm) SAL_OVERRIDE; private: - std::vector m_aContents; + std::vector< rtl::Reference > m_aContents; }; -inline XFContent* XFContentContainer::GetContent(sal_uInt32 index) const +inline rtl::Reference XFContentContainer::GetContent(sal_uInt32 index) const { if (index > m_aContents.size()-1) return NULL; diff --git a/lotuswordpro/source/filter/xfilter/xfframe.cxx b/lotuswordpro/source/filter/xfilter/xfframe.cxx index 5c8d02bfb695..2af0994cc62f 100644 --- a/lotuswordpro/source/filter/xfilter/xfframe.cxx +++ b/lotuswordpro/source/filter/xfilter/xfframe.cxx @@ -194,12 +194,12 @@ void XFFrame::AdjustZIndex() { for( int i=0; i pContent = GetContent(i); + if( pContent.is() ) { if( pContent->GetContentType() == enumXFContentFrame ) { - XFFrame *pFrame = (XFFrame*)pContent; + XFFrame *pFrame = (XFFrame*)pContent.get(); pFrame->m_nZIndex = m_nZIndex + 1; pFrame->AdjustZIndex(); } diff --git a/lotuswordpro/source/filter/xfilter/xftextspan.cxx b/lotuswordpro/source/filter/xfilter/xftextspan.cxx index ce5663d15862..4de6bad98df7 100644 --- a/lotuswordpro/source/filter/xfilter/xftextspan.cxx +++ b/lotuswordpro/source/filter/xfilter/xftextspan.cxx @@ -77,16 +77,6 @@ XFTextSpan::XFTextSpan(const OUString& text, XFTextSpan::~XFTextSpan() { - std::vector::iterator it; - for( it = m_aContents.begin(); it != m_aContents.end(); ++it ) - { - XFContent *pContent = *it; - if( pContent ) - { - delete pContent; - } - } - m_aContents.clear(); } enumXFContent XFTextSpan::GetContentType() @@ -117,10 +107,10 @@ void XFTextSpan::ToXml(IXFStream *pStrm) pAttrList->AddAttribute( "text:style-name", GetStyleName() ); pStrm->StartElement( "text:span" ); - std::vector::iterator it; + std::vector< rtl::Reference >::iterator it; for( it= m_aContents.begin(); it!= m_aContents.end(); ++it ) { - XFContent *pContent = *it; + XFContent *pContent = it->get(); if( pContent ) pContent->ToXml(pStrm); } @@ -140,20 +130,20 @@ void XFTextSpanStart::ToXml(IXFStream *pStrm) pAttrList->AddAttribute( "text:style-name", GetStyleName() ); pStrm->StartElement( "text:span" ); - std::vector::iterator it; + std::vector< rtl::Reference >::iterator it; for( it= m_aContents.begin(); it!= m_aContents.end(); ++it ) { - XFContent *pContent = *it; + XFContent *pContent = it->get(); if( pContent ) pContent->ToXml(pStrm); } } void XFTextSpanEnd::ToXml(IXFStream *pStrm) { - std::vector::iterator it; + std::vector< rtl::Reference >::iterator it; for( it= m_aContents.begin(); it!= m_aContents.end(); ++it ) { - XFContent *pContent = *it; + XFContent *pContent = it->get(); if( pContent ) pContent->ToXml(pStrm); } diff --git a/lotuswordpro/source/filter/xfilter/xftextspan.hxx b/lotuswordpro/source/filter/xfilter/xftextspan.hxx index 0ad0fb4f6e2d..535cd3d4fe74 100644 --- a/lotuswordpro/source/filter/xfilter/xftextspan.hxx +++ b/lotuswordpro/source/filter/xfilter/xftextspan.hxx @@ -60,9 +60,14 @@ #ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_XFILTER_XFTEXTSPAN_HXX #define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_XFILTER_XFTEXTSPAN_HXX +#include + +#include + +#include + #include "xfglobal.hxx" #include "xfcontent.hxx" -#include class IXFStream; @@ -80,7 +85,7 @@ public: virtual enumXFContent GetContentType() SAL_OVERRIDE; virtual void ToXml(IXFStream *pStrm) SAL_OVERRIDE; protected: - std::vector m_aContents; + std::vector< rtl::Reference > m_aContents; }; class XFTextSpanStart : public XFTextSpan //for adding style of power field -- cgit