From 83de5fe9c3161b9bfe655306253fc760fc64e8f3 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 13 Jun 2014 14:47:05 +0200 Subject: 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 (cherry picked from commit ba9b63d8101197d3fd8612193b1ca188271dfc1a) --- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 29 +++++++++++++++++++------- writerfilter/source/rtftok/rtfsdrimport.cxx | 5 ++++- writerfilter/source/rtftok/rtfsdrimport.hxx | 2 ++ 3 files changed, 27 insertions(+), 9 deletions(-) (limited to 'writerfilter') diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 16b09eaec7b6..aafc9726bed5 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -775,16 +775,29 @@ int RTFDocumentImpl::resolvePict(bool bInline) // Wrap it in an XShape. uno::Reference xShape; - if (m_xModelFactory.is()) - xShape.set(m_xModelFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY); - uno::Reference xPropertySet(xShape, uno::UNO_QUERY); - uno::Reference 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 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 const xDrawSupplier( + m_xDstDoc, uno::UNO_QUERY); + if (xDrawSupplier.is()) + { + uno::Reference xShapes( + xDrawSupplier->getDrawPage(), uno::UNO_QUERY); + if (xShapes.is()) + xShapes->add(xShape); + } + } + + uno::Reference 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) diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx index 5d0424ad2619..a47731d9c7a0 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.cxx +++ b/writerfilter/source/rtftok/rtfsdrimport.cxx @@ -226,7 +226,10 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, uno::Reference xShape; uno::Reference 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; diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx index 770aff4f1c59..0b6958993bb2 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.hxx +++ b/writerfilter/source/rtftok/rtfsdrimport.hxx @@ -43,6 +43,8 @@ public: void pushParent(css::uno::Reference xParent); /// Pop the current group shape from the parent stack. void popParent(); + css::uno::Reference const& getCurrentShape() + { return m_xShape; } private: void createShape(const OUString& aService, css::uno::Reference& xShape, css::uno::Reference& xPropertySet); void applyProperty(css::uno::Reference xShape, const OUString& aKey, const OUString& aValue); -- cgit v1.2.3