[Libreoffice-commits] core.git: sc/inc sc/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Wed May 18 20:45:24 UTC 2016
sc/inc/textuno.hxx | 23 +++++------
sc/source/core/data/attrib.cxx | 9 +++-
sc/source/filter/xml/XMLTableHeaderFooterContext.cxx | 2 -
sc/source/filter/xml/XMLTableMasterPageExport.cxx | 13 ------
sc/source/ui/unoobj/fielduno.cxx | 12 ++++--
sc/source/ui/unoobj/textuno.cxx | 38 ++++++++++---------
6 files changed, 44 insertions(+), 53 deletions(-)
New commits:
commit fc29ace3438eea09afe3ddbb5118458cbb531b06
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Wed May 18 02:47:01 2016 +0200
better fix for memory leak around calc header-footer UNO objects
Change-Id: I396a2c57b38623d82fe973ad8d53f08b1b480e2e
Reviewed-on: https://gerrit.libreoffice.org/25116
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx
index 861a178..8182e54 100644
--- a/sc/inc/textuno.hxx
+++ b/sc/inc/textuno.hxx
@@ -29,6 +29,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/weakref.hxx>
#include <rtl/ref.hxx>
#include "scdllapi.h"
@@ -65,11 +66,7 @@ private:
rtl::Reference<ScHeaderFooterTextObj> mxRightText;
public:
- ScHeaderFooterContentObj( const EditTextObject* pLeft,
- const EditTextObject* pCenter,
- const EditTextObject* pRight );
-
- ScHeaderFooterContentObj() = delete;
+ ScHeaderFooterContentObj();
virtual ~ScHeaderFooterContentObj();
// for ScPageHFItem (using getImplementation)
@@ -77,6 +74,10 @@ public:
const EditTextObject* GetCenterEditObject() const;
const EditTextObject* GetRightEditObject() const;
+ void Init( const EditTextObject* pLeft,
+ const EditTextObject* pCenter,
+ const EditTextObject* pRight);
+
// XHeaderFooterContent
virtual css::uno::Reference< css::text::XText > SAL_CALL
getLeftText() throw(css::uno::RuntimeException, std::exception) override;
@@ -101,7 +102,6 @@ public:
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
throw(css::uno::RuntimeException, std::exception) override;
- virtual void dispose();
};
// ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
@@ -110,7 +110,7 @@ class ScHeaderFooterTextData
{
private:
std::unique_ptr<EditTextObject> mpTextObj;
- rtl::Reference<ScHeaderFooterContentObj> rContentObj;
+ css::uno::WeakReference<css::sheet::XHeaderFooterContent> xContentObj;
ScHeaderFooterPart nPart;
ScEditEngineDefaulter* pEditEngine;
SvxEditEngineForwarder* pForwarder;
@@ -120,7 +120,7 @@ public:
ScHeaderFooterTextData(const ScHeaderFooterTextData&) = delete;
const ScHeaderFooterTextData& operator=(const ScHeaderFooterTextData&) = delete;
ScHeaderFooterTextData(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
+ css::uno::WeakReference<css::sheet::XHeaderFooterContent> xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
~ScHeaderFooterTextData();
// helper functions
@@ -130,11 +130,9 @@ public:
ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine; }
ScHeaderFooterPart GetPart() const { return nPart; }
- const rtl::Reference<ScHeaderFooterContentObj>& GetContentObj() const { return rContentObj; }
+ const css::uno::Reference<css::sheet::XHeaderFooterContent> GetContentObj() const { return xContentObj; }
const EditTextObject* GetTextObject() const { return mpTextObj.get(); }
-
- void dispose() { rContentObj.clear(); }
};
/**
@@ -158,7 +156,7 @@ private:
public:
ScHeaderFooterTextObj(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
+ css::uno::WeakReference<css::sheet::XHeaderFooterContent> xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
virtual ~ScHeaderFooterTextObj();
const EditTextObject* GetTextObject() const;
@@ -229,7 +227,6 @@ public:
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
throw(css::uno::RuntimeException, std::exception) override;
- virtual void dispose() { aTextData.dispose(); }
};
// derived cursor objects for getImplementation and getText/getStart/getEnd
diff --git a/sc/source/core/data/attrib.cxx b/sc/source/core/data/attrib.cxx
index abf9c29..02afdd1 100644
--- a/sc/source/core/data/attrib.cxx
+++ b/sc/source/core/data/attrib.cxx
@@ -561,10 +561,13 @@ ScPageHFItem::~ScPageHFItem()
bool ScPageHFItem::QueryValue( uno::Any& rVal, sal_uInt8 /* nMemberId */ ) const
{
- uno::Reference<sheet::XHeaderFooterContent> xContent =
- new ScHeaderFooterContentObj( pLeftArea, pCenterArea, pRightArea );
+ rtl::Reference<ScHeaderFooterContentObj> xContent =
+ new ScHeaderFooterContentObj();
+ xContent->Init(pLeftArea, pCenterArea, pRightArea);
- rVal <<= xContent;
+ uno::Reference<sheet::XHeaderFooterContent> xCont(xContent.get());
+
+ rVal <<= xCont;
return true;
}
diff --git a/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx b/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx
index e6aea5b..2c97450 100644
--- a/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx
+++ b/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx
@@ -100,8 +100,6 @@ XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport,
XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
{
- rtl::Reference<ScHeaderFooterContentObj> pImp = ScHeaderFooterContentObj::getImplementation( xHeaderFooterContent );
- pImp->dispose();
}
SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
diff --git a/sc/source/filter/xml/XMLTableMasterPageExport.cxx b/sc/source/filter/xml/XMLTableMasterPageExport.cxx
index 821bcf5..12c8c15 100644
--- a/sc/source/filter/xml/XMLTableMasterPageExport.cxx
+++ b/sc/source/filter/xml/XMLTableMasterPageExport.cxx
@@ -107,14 +107,6 @@ void XMLTableMasterPageExport::exportHeaderFooter(const css::uno::Reference < cs
}
}
-void lcl_DisposeXHeaderFooterContent( const Reference < sheet::XHeaderFooterContent >& xHFContent )
-{
- if( !xHFContent.is() )
- return;
- rtl::Reference<ScHeaderFooterContentObj> pImp = ScHeaderFooterContentObj::getImplementation( xHFContent );
- pImp->dispose();
-}
-
void XMLTableMasterPageExport::exportMasterPageContent(
const Reference < XPropertySet > & rPropSet,
bool bAutoStyles )
@@ -172,11 +164,6 @@ void XMLTableMasterPageExport::exportMasterPageContent(
exportHeaderFooter( xFooterLeft, XML_FOOTER_LEFT, bLeftFooter );
}
-
- lcl_DisposeXHeaderFooterContent( xHeader );
- lcl_DisposeXHeaderFooterContent( xHeaderLeft );
- lcl_DisposeXHeaderFooterContent( xFooter );
- lcl_DisposeXHeaderFooterContent( xFooterLeft );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index 74e351c..c71ac79 100644
--- a/sc/source/ui/unoobj/fielduno.cxx
+++ b/sc/source/ui/unoobj/fielduno.cxx
@@ -479,19 +479,23 @@ uno::Reference<text::XTextField> ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_In
// Get the parent text range instance.
uno::Reference<text::XTextRange> xTextRange;
- rtl::Reference<ScHeaderFooterContentObj> rContentObj = mrData.GetContentObj();
+ uno::Reference<sheet::XHeaderFooterContent> xContentObj = mrData.GetContentObj();
+ if (!xContentObj.is())
+ throw uno::RuntimeException("");
+
+ rtl::Reference<ScHeaderFooterContentObj> pContentObj = ScHeaderFooterContentObj::getImplementation(xContentObj);
uno::Reference<text::XText> xText;
switch ( mrData.GetPart() )
{
case ScHeaderFooterPart::LEFT:
- xText = rContentObj->getLeftText();
+ xText = pContentObj->getLeftText();
break;
case ScHeaderFooterPart::CENTER:
- xText = rContentObj->getCenterText();
+ xText = pContentObj->getCenterText();
break;
case ScHeaderFooterPart::RIGHT:
- xText = rContentObj->getRightText();
+ xText = pContentObj->getRightText();
break;
}
diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx
index d5c73d9..f52b030 100644
--- a/sc/source/ui/unoobj/textuno.cxx
+++ b/sc/source/ui/unoobj/textuno.cxx
@@ -92,12 +92,7 @@ static const SvxItemPropertySet * lcl_GetHdFtPropertySet()
SC_SIMPLE_SERVICE_INFO( ScHeaderFooterContentObj, "ScHeaderFooterContentObj", "com.sun.star.sheet.HeaderFooterContent" )
SC_SIMPLE_SERVICE_INFO( ScHeaderFooterTextObj, "ScHeaderFooterTextObj", "stardiv.one.Text.Text" )
-ScHeaderFooterContentObj::ScHeaderFooterContentObj( const EditTextObject* pLeft,
- const EditTextObject* pCenter,
- const EditTextObject* pRight ) :
- mxLeftText(new ScHeaderFooterTextObj(this, ScHeaderFooterPart::LEFT, pLeft)),
- mxCenterText(new ScHeaderFooterTextObj(this, ScHeaderFooterPart::CENTER, pCenter)),
- mxRightText(new ScHeaderFooterTextObj(this, ScHeaderFooterPart::RIGHT, pRight))
+ScHeaderFooterContentObj::ScHeaderFooterContentObj()
{
}
@@ -178,17 +173,20 @@ rtl::Reference<ScHeaderFooterContentObj> ScHeaderFooterContentObj::getImplementa
return pRet;
}
-void ScHeaderFooterContentObj::dispose()
+void ScHeaderFooterContentObj::Init( const EditTextObject* pLeft,
+ const EditTextObject* pCenter,
+ const EditTextObject* pRight )
{
- mxLeftText->dispose();
- mxCenterText->dispose();
- mxRightText->dispose();
+ uno::Reference<css::sheet::XHeaderFooterContent> xThis(this);
+ mxLeftText = rtl::Reference<ScHeaderFooterTextObj>(new ScHeaderFooterTextObj(xThis, ScHeaderFooterPart::LEFT, pLeft));
+ mxCenterText = rtl::Reference<ScHeaderFooterTextObj>(new ScHeaderFooterTextObj(xThis, ScHeaderFooterPart::CENTER, pCenter));
+ mxRightText = rtl::Reference<ScHeaderFooterTextObj>(new ScHeaderFooterTextObj(xThis, ScHeaderFooterPart::RIGHT, pRight));
}
ScHeaderFooterTextData::ScHeaderFooterTextData(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
+ uno::WeakReference<sheet::XHeaderFooterContent> xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
mpTextObj(pTextObj ? pTextObj->Clone() : nullptr),
- rContentObj( rContent ),
+ xContentObj( xContent ),
nPart( nP ),
pEditEngine( nullptr ),
pForwarder( nullptr ),
@@ -261,8 +259,8 @@ void ScHeaderFooterTextData::UpdateData(EditEngine& rEditEngine)
}
ScHeaderFooterTextObj::ScHeaderFooterTextObj(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
- aTextData(rContent, nP, pTextObj)
+ uno::WeakReference<sheet::XHeaderFooterContent> xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
+ aTextData(xContent, nP, pTextObj)
{
// ScHeaderFooterTextData acquires rContent
// pUnoText is created on demand (getString/setString work without it)
@@ -329,18 +327,22 @@ OUString SAL_CALL ScHeaderFooterTextObj::getString() throw(uno::RuntimeException
OUString aRet;
const EditTextObject* pData;
- rtl::Reference<ScHeaderFooterContentObj> rContentObj = aTextData.GetContentObj();
+ uno::Reference<css::sheet::XHeaderFooterContent> xContentObj = aTextData.GetContentObj();
+ if (!xContentObj.is())
+ throw css::uno::RuntimeException("");
+
+ rtl::Reference<ScHeaderFooterContentObj> pObj = ScHeaderFooterContentObj::getImplementation(xContentObj);
switch ( aTextData.GetPart() )
{
case ScHeaderFooterPart::LEFT:
- pData = rContentObj->GetLeftEditObject();
+ pData = pObj->GetLeftEditObject();
break;
case ScHeaderFooterPart::CENTER:
- pData = rContentObj->GetCenterEditObject();
+ pData = pObj->GetCenterEditObject();
break;
case ScHeaderFooterPart::RIGHT:
- pData = rContentObj->GetRightEditObject();
+ pData = pObj->GetRightEditObject();
break;
default:
SAL_WARN("sc.ui","unexpected enum value of ScHeaderFooterPart");
More information about the Libreoffice-commits
mailing list