desktop/source/lib/init.cxx |   13 +++++++++++++
 include/sfx2/objsh.hxx      |    4 ++++
 sfx2/source/doc/objxtor.cxx |    5 +++++
 3 files changed, 22 insertions(+)

New commits:
commit 7d784910689172014b8cf6144e654402696d8801
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Thu Mar 28 09:38:15 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Mar 28 17:15:58 2024 +0100

    lok: add method to allow explicit cleanup of temporary files.o
    
    Special case fast destruction of background saving children.
    
    Change-Id: I8fba4d0818d23a8b0e1bb4d074e1afae7dacde33
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165448
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 52882a4a9f88..68191600f0f8 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1471,6 +1471,19 @@ LibLODocument_Impl::LibLODocument_Impl(uno::Reference 
<css::lang::XComponent> xC
 
 LibLODocument_Impl::~LibLODocument_Impl()
 {
+    if (comphelper::LibreOfficeKit::isForkedChild())
+    {
+        // Touch the least memory possible, while trying to avoid leaking 
files.
+        SfxBaseModel* pBaseModel = 
dynamic_cast<SfxBaseModel*>(mxComponent.get());
+        if (pBaseModel)
+        {
+            SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+            if (pObjectShell)
+                pObjectShell->InternalCloseAndRemoveFiles();
+        }
+        return;
+    }
+
     try
     {
         mxComponent->dispose();
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 3175cb283642..32d9afd6ed6f 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -239,6 +239,7 @@ private:
 
 public:
     static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
+
     /* Stampit disable/enable cancel button for print jobs
        default = true = enable! */
     void                        Stamp_SetPrintCancelState(bool bState);
@@ -699,6 +700,9 @@ public:
                                 bool bShowCloseButton = true);
     std::vector<InfobarData>& getPendingInfobars();
 
+    // Destruction of storages and streams
+    void InternalCloseAndRemoveFiles();
+
     SAL_DLLPRIVATE bool CreatePreview_Impl(bool bFullContent, VirtualDevice* 
pDevice, GDIMetaFile* pFile) const;
 
     SAL_DLLPRIVATE static bool IsPackageStorageFormat_Impl(const SfxMedium &);
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index 11b38ced10a0..434c0f17992d 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -306,6 +306,11 @@ SfxObjectShell::~SfxObjectShell()
 
     pImpl->pBaseModel.clear();
 
+    InternalCloseAndRemoveFiles();
+}
+
+void SfxObjectShell::InternalCloseAndRemoveFiles()
+{
     // don't call GetStorage() here, in case of Load Failure it's possible 
that a storage was never assigned!
     if ( pMedium && pMedium->HasStorage_Impl() && pMedium->GetStorage( false ) 
== pImpl->m_xDocStorage )
         pMedium->CanDisposeStorage_Impl( false );

Reply via email to