From c9a27eb938b98d7812d3ab965fc88bb511e0b996 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 26 Oct 2012 16:14:06 +0200 Subject: [PATCH] Work around premature disposing of PackageRegistryBackends With ucbhelper::Content now requiring an XComponentContext during construction, calling "unopkg add" with an .oxt that requires license acceptance would lead to an assertion about a null XComponentContext, as doChecksForAddExtension calls the XPackage's checkPrerequisites -> checkLicnese -> getTextFromURL, which creates an ucbhelper::Content with getMyBackend()->getComponentContext(), but early release of the "tmp" manager would already have caused disposing of that backend, which clears m_xComponentContext. I assume this problem had always been lurking silently in the code. Change-Id: I9f59c612fe3831b2f6dd832ef2f0505b6590b8e0 --- .../manager/dp_extensionmanager.cxx | 37 ++++++++----------- .../manager/dp_extensionmanager.hxx | 5 --- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/desktop/source/deployment/manager/dp_extensionmanager.cxx b/desktop/source/deployment/manager/dp_extensionmanager.cxx index de78275bb205..4ba55848494d 100644 --- a/desktop/source/deployment/manager/dp_extensionmanager.cxx +++ b/desktop/source/deployment/manager/dp_extensionmanager.cxx @@ -655,8 +655,22 @@ Reference ExtensionManager::addExtension( //would remove the first one. ::osl::MutexGuard addGuard(m_addMutex); - Reference xTmpExtension = - getTempExtension(url, xAbortChannel, xCmdEnv); + Reference xTmpRepository(getTmpRepository()); + // make sure xTmpRepository is alive as long as xTmpExtension is; as + // the "tmp" manager is only held weakly by m_xPackageManagerFactory, it + // could otherwise be disposed early, which would in turn dispose + // xTmpExtension's PackageRegistryBackend behind its back + Reference xTmpExtension( + xTmpRepository->addPackage( + url, uno::Sequence(), OUString(), xAbortChannel, + new TmpRepositoryCommandEnv())); + if (!xTmpExtension.is()) { + throw deploy::DeploymentException( + ("Extension Manager: Failed to create temporary XPackage for url: " + + url), + static_cast(this), uno::Any()); + } + //Make sure the extension is removed from the tmp repository in case //of an exception ExtensionRemoveGuard tmpExtensionRemoveGuard(xTmpExtension, getTmpRepository()); @@ -1404,25 +1418,6 @@ void ExtensionManager::checkUpdate( static_cast(this), request ); } -Reference ExtensionManager::getTempExtension( - OUString const & url, - Reference const & xAbortChannel, - Reference const & /*xCmdEnv*/) - -{ - Reference tmpCmdEnvA(new TmpRepositoryCommandEnv()); - Reference xTmpPackage = getTmpRepository()->addPackage( - url, uno::Sequence(),OUString(), xAbortChannel, tmpCmdEnvA); - if (!xTmpPackage.is()) - { - throw deploy::DeploymentException( - OUSTR("Extension Manager: Failed to create temporary XPackage for url: ") + url, - static_cast(this), uno::Any()); - - } - return xTmpPackage; -} - uno::Sequence > SAL_CALL ExtensionManager::getExtensionsWithUnacceptedLicenses( OUString const & repository, diff --git a/desktop/source/deployment/manager/dp_extensionmanager.hxx b/desktop/source/deployment/manager/dp_extensionmanager.hxx index c8d8b300da60..584f01ce07c1 100644 --- a/desktop/source/deployment/manager/dp_extensionmanager.hxx +++ b/desktop/source/deployment/manager/dp_extensionmanager.hxx @@ -280,11 +280,6 @@ private: css::uno::Reference const & oldExtension, css::uno::Reference const & xCmdEnv); - css::uno::Reference getTempExtension( - ::rtl::OUString const & url, - css::uno::Reference const & xAbortChannel, - css::uno::Reference const & xCmdEnv); - void addExtensionsToMap( id2extensions & mapExt, css::uno::Sequence > const & seqExt,