Kaydet (Commit) 87c18643 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

try to prevent use-after-free

Change-Id: I7edc3d09d495749a44da29c0cbb30eb0d20fd779
üst 29b8f25f
......@@ -22,8 +22,10 @@
#include <cppuhelper/implbase1.hxx>
#include <svl/itemprop.hxx>
#include <svl/lstner.hxx>
class ScDocument;
class ScDocShell;
class ScConditionalFormatList;
class ScConditionalFormat;
class ScIconSetFormat;
......@@ -43,13 +45,16 @@ class XSheetCellRanges;
} } }
class ScCondFormatsObj : public cppu::WeakImplHelper1<com::sun::star::sheet::XConditionalFormats>
class ScCondFormatsObj : public cppu::WeakImplHelper1<com::sun::star::sheet::XConditionalFormats>,
public SfxListener
{
public:
ScCondFormatsObj(ScDocument& rDoc, SCTAB nTab);
ScCondFormatsObj(ScDocShell* pDocShell, SCTAB nTab);
virtual ~ScCondFormatsObj();
virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) SAL_OVERRIDE;
static ScCondFormatsObj* getImplementation( uno::Reference< com::sun::star::sheet::XConditionalFormats > xCondFormat );
// XConditionalFormats
......@@ -73,7 +78,7 @@ public:
private:
ScConditionalFormatList* getCoreObject();
SCTAB mnTab;
ScDocument& mrDoc;
ScDocShell* mpDocShell;
};
class ScCondFormatObj : public com::sun::star::sheet::XConditionalFormat,
......
......@@ -8608,7 +8608,7 @@ void ScTableSheetObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEn
}
else if (pEntry->nWID == SC_WID_UNO_CONDFORMAT)
{
rAny <<= uno::Reference<sheet::XConditionalFormats>(new ScCondFormatsObj(pDocSh->GetDocument(), nTab));
rAny <<= uno::Reference<sheet::XConditionalFormats>(new ScCondFormatsObj(pDocSh, nTab));
}
else
ScCellRangeObj::GetOnePropertyValue(pEntry, rAny);
......
......@@ -186,14 +186,26 @@ const IconSetTypeApiMap aIconSetApiMap[] =
}
ScCondFormatsObj::ScCondFormatsObj(ScDocument& rDoc, SCTAB nTab):
ScCondFormatsObj::ScCondFormatsObj(ScDocShell* pDocShell, SCTAB nTab):
mnTab(nTab),
mrDoc(rDoc)
mpDocShell(pDocShell)
{
pDocShell->GetDocument().AddUnoObject(*this);
}
ScCondFormatsObj::~ScCondFormatsObj()
{
if (mpDocShell)
mpDocShell->GetDocument().RemoveUnoObject(*this);
}
void ScCondFormatsObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
{
if ( dynamic_cast<const SfxSimpleHint*>(&rHint) &&
static_cast<const SfxSimpleHint&>(rHint).GetId() == SFX_HINT_DYING )
{
mpDocShell = NULL; // ungueltig geworden
}
}
sal_Int32 ScCondFormatsObj::addByRange(const uno::Reference< sheet::XConditionalFormat >& xCondFormat,
......@@ -236,7 +248,10 @@ sal_Int32 ScCondFormatsObj::getLength()
ScConditionalFormatList* ScCondFormatsObj::getCoreObject()
{
ScConditionalFormatList* pList = mrDoc.GetCondFormList(mnTab);
if (!mpDocShell)
throw uno::RuntimeException();
ScConditionalFormatList* pList = mpDocShell->GetDocument().GetCondFormList(mnTab);
if (!pList)
throw uno::RuntimeException();
......
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