qadevOOo/tests/java/mod/_sw/SwXAutoTextEntry.java | 6 ++++++ sw/source/uibase/inc/unoatxt.hxx | 7 ++++++- sw/source/uibase/uno/unoatxt.cxx | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-)
New commits: commit 1677faabbf7ae56e233205251b78b77d28937c35 Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Jan 4 11:58:19 2017 +0100 SwXAutoTextEntry needs a disposal protocol SwXAutoTextEntry::GetBodyText calls SwGlossaries::EditGroupDoc to create a Sw[Web]GlosDocShell (which it then stores in xDocSh), and there must be a call to that shell's DoClose to clean up its resources. However, if a reference to the SwXAutoTextEntry is still held during XDesktop::terminate (as can happen in JunitTest_sw_unoapi_1, where such a reference is held from Java, thus arbitrarily delaying destruction of the SwXAutoTextEntry until the JVM does GC), SwXAutoTextEntry::Notify's PrepareCloseDoc case will release xDocSh without calling DoClose, so an eventual ~SwXAutoTextEntry will not call DoClose either. (And calling DoClose from withing SwXAutoTextEntry::Notify would cause a crash, as it would destroy the SwGlosDocShell recursively from within its SfxBroadcaster::Broadcast call.) So introduce a disposal protocol for XAutoTextEntry and call it at least in the place that caused the resource leak in JunitTest_sw_unoapi_1. For lack of a better inerface, reuse css.lang.XComponent for that protocol, even though this scenario doesn't involve breaking cyclic references among UNO objects caused by listener patterns. Change-Id: Id6501b84e562950e40b83e0b1afd1b3184807856 diff --git a/qadevOOo/tests/java/mod/_sw/SwXAutoTextEntry.java b/qadevOOo/tests/java/mod/_sw/SwXAutoTextEntry.java index 188307e..30a7ada 100644 --- a/qadevOOo/tests/java/mod/_sw/SwXAutoTextEntry.java +++ b/qadevOOo/tests/java/mod/_sw/SwXAutoTextEntry.java @@ -87,11 +87,17 @@ public class SwXAutoTextEntry extends TestCase { try { if ( oGroup.hasByName("NewEntryName") ) { log.println("Removing 'NewEntryName' element"); + ((com.sun.star.lang.XComponent) AnyConverter.toObject( + new Type(com.sun.star.lang.XComponent.class), + oGroup.getByName("NewEntryName"))).dispose(); oGroup.removeByName("NewEntryName"); } } catch ( com.sun.star.container.NoSuchElementException e ) { log.println("Cannot remove TextEntry from group..."); e.printStackTrace(log); + } catch ( com.sun.star.lang.WrappedTargetException e ) { + log.println("Cannot remove TextEntry from group..."); + e.printStackTrace(log); } log.println( "disposing xTextDoc " ); util.DesktopTools.closeDoc(xTextDoc); diff --git a/sw/source/uibase/inc/unoatxt.hxx b/sw/source/uibase/inc/unoatxt.hxx index 02e49d0..a991b1d 100644 --- a/sw/source/uibase/inc/unoatxt.hxx +++ b/sw/source/uibase/inc/unoatxt.hxx @@ -31,6 +31,8 @@ #include <com/sun/star/text/XText.hpp> #include <svl/itemprop.hxx> #include <svl/lstner.hxx> +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/compbase.hxx> #include <cppuhelper/implbase.hxx> #include <svtools/unoevent.hxx> class SwTextBlocks; @@ -155,7 +157,8 @@ public: class SwXAutoTextEntry :public SfxListener - ,public cppu::WeakImplHelper + ,public cppu::BaseMutex + ,public cppu::WeakComponentImplHelper < css::text::XAutoTextEntry, css::lang::XServiceInfo, @@ -178,6 +181,8 @@ class SwXAutoTextEntry } void GetBodyText (); + void SAL_CALL disposing() override; + protected: /** ensure that the current content (which may only be in-memory so far) is flushed to the auto text group file diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx index f984a3e..ef41ed8 100644 --- a/sw/source/uibase/uno/unoatxt.cxx +++ b/sw/source/uibase/uno/unoatxt.cxx @@ -718,6 +718,7 @@ sal_Int64 SAL_CALL SwXAutoTextEntry::getSomething( const uno::Sequence< sal_Int8 SwXAutoTextEntry::SwXAutoTextEntry(SwGlossaries* pGlss, const OUString& rGroupName, const OUString& rEntryName) : + WeakComponentImplHelper(m_aMutex), pGlossaries(pGlss), sGroupName(rGroupName), sEntryName(rEntryName), @@ -801,6 +802,12 @@ void SwXAutoTextEntry::GetBodyText () xBodyText.set( *pBodyText, uno::UNO_QUERY); } +void SwXAutoTextEntry::disposing() +{ + SolarMutexGuard g; + implFlushDocument(true); +} + uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursor() throw( uno::RuntimeException, std::exception ) { SolarMutexGuard aGuard; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits