Kaydet (Commit) ba9b63d8 authored tarafından Michael Stahl's avatar Michael Stahl

fdo#76633: writerfilter: RTF import: do not leak the XShape of image

RTFSdrImport::resolve() is called for \picprop and creates an XShape
that is stored in RTFSdrImport::m_xShape and also
DomainMapper_Impl::m_aPendingShapes;
later RTFDocumentImpl::resolvePict() completely ignores that XShape
and creates a new one, which is also inserted in the document;
the first XShape is effectively leaked.

Try to avoid that by re-using the exising m_xShape in resolvePict().
Not sure if there are any problems with doing this, it's all a bit
confusing.

Change-Id: I98456242acb0766f547eb8f7d877f51d53323f3a
üst b7857e5c
......@@ -577,14 +577,11 @@ DECLARE_RTFIMPORT_TEST(testFdo76633, "fdo76633.rtf")
// check that there is only a graphic object, not an additional rectangle
uno::Reference<lang::XServiceInfo> xShape(getShape(1), uno::UNO_QUERY);
CPPUNIT_ASSERT(xShape.is());
#if 0
// disabled - fails currently
CPPUNIT_ASSERT(xShape->supportsService("com.sun.star.text.TextGraphicObject"));
try {
uno::Reference<drawing::XShape> xShape2(getShape(2), uno::UNO_QUERY);
CPPUNIT_FAIL("exception expected");
} catch (lang::IndexOutOfBoundsException const&) { /* expected */ }
#endif
}
DECLARE_RTFIMPORT_TEST(testFdo48033, "fdo48033.rtf")
......
......@@ -771,16 +771,29 @@ int RTFDocumentImpl::resolvePict(bool bInline)
// Wrap it in an XShape.
uno::Reference<drawing::XShape> xShape;
if (m_xModelFactory.is())
xShape.set(m_xModelFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
uno::Reference<drawing::XDrawPageSupplier> xDrawSupplier(m_xDstDoc, uno::UNO_QUERY);
if (xDrawSupplier.is())
xShape = m_pSdrImport->getCurrentShape();//Mapper().PopPendingShape();
if (xShape.is())
{
uno::Reference< drawing::XShapes > xShapes(xDrawSupplier->getDrawPage(), uno::UNO_QUERY);
if (xShapes.is())
xShapes->add(xShape);
uno::Reference<lang::XServiceInfo> xSI(xShape, uno::UNO_QUERY_THROW);
assert(xSI->supportsService("com.sun.star.drawing.GraphicObjectShape"));
}
else
{
if (m_xModelFactory.is())
xShape.set(m_xModelFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
uno::Reference<drawing::XDrawPageSupplier> const xDrawSupplier(
m_xDstDoc, uno::UNO_QUERY);
if (xDrawSupplier.is())
{
uno::Reference<drawing::XShapes> xShapes(
xDrawSupplier->getDrawPage(), uno::UNO_QUERY);
if (xShapes.is())
xShapes->add(xShape);
}
}
uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
// check if the picture is in an OLE object and if the \objdata element is used
// (see RTF_OBJECT in RTFDocumentImpl::dispatchDestination)
......
......@@ -226,7 +226,10 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose,
uno::Reference<drawing::XShape> xShape;
uno::Reference<beans::XPropertySet> xPropertySet;
// Create this early, as custom shapes may have properties before the type arrives.
createShape("com.sun.star.drawing.CustomShape", xShape, xPropertySet);
if (PICT == shapeOrPict)
createShape("com.sun.star.drawing.GraphicObjectShape", xShape, xPropertySet);
else
createShape("com.sun.star.drawing.CustomShape", xShape, xPropertySet);
uno::Any aAny;
beans::PropertyValue aPropertyValue;
awt::Rectangle aViewBox;
......
......@@ -43,6 +43,8 @@ public:
void pushParent(css::uno::Reference<css::drawing::XShapes> xParent);
/// Pop the current group shape from the parent stack.
void popParent();
css::uno::Reference<css::drawing::XShape> const& getCurrentShape()
{ return m_xShape; }
private:
void createShape(const OUString& aService, css::uno::Reference<css::drawing::XShape>& xShape, css::uno::Reference<css::beans::XPropertySet>& xPropertySet);
void applyProperty(css::uno::Reference<css::drawing::XShape> xShape, const OUString& aKey, const OUString& aValue);
......
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