include/sax/fshelper.hxx                 |    5 ++++-
 oox/source/core/xmlfilterbase.cxx        |    6 ++++++
 oox/source/export/chartexport.cxx        |    3 +++
 sax/source/tools/fshelper.cxx            |   21 ++++++++++++++++++---
 sc/source/filter/excel/xestream.cxx      |    6 ++++++
 sd/source/filter/eppt/pptx-epptooxml.cxx |   23 +++++++++++++++++++++++
 sw/source/filter/ww8/docxexport.cxx      |   20 ++++++++++++++++++++
 7 files changed, 80 insertions(+), 4 deletions(-)

New commits:
commit 5d44c226dc325a80c9342b784c828f674a92c94d
Author:     Caolán McNamara <[email protected]>
AuthorDate: Tue Oct 11 10:45:40 2022 +0100
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Jan 16 01:54:56 2023 +0000

    crashtesting: exception during dtor
    
    Change-Id: I9874778ba79540cfde32bf59c3a63ebb72889dc7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141215
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>
    (cherry picked from commit 06423ddc61a378894c91a6a23fb31afb1701d8f2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145546
    Tested-by: Tomaž Vajngerl <[email protected]>
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx
index 115a3f912ca5..2d01066a1453 100644
--- a/include/sax/fshelper.hxx
+++ b/include/sax/fshelper.hxx
@@ -50,6 +50,9 @@ public:
 
     ~FastSerializerHelper();
 
+    void startDocument();
+    void endDocument();
+
     /// Start an element. After the first argument there can be a number of 
(attribute, value) pairs.
     template<typename... Args>
     void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const 
char* value, Args &&... args)
diff --git a/oox/source/core/xmlfilterbase.cxx 
b/oox/source/core/xmlfilterbase.cxx
index 877e8d52eda3..1ca7a36522f0 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -697,6 +697,8 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< 
XDocumentProperties
     }
 
     pCoreProps->endElementNS( XML_cp, XML_coreProperties );
+
+    pCoreProps->endDocument();
 }
 
 static void
@@ -819,6 +821,8 @@ writeAppProperties( XmlFilterBase& rSelf, const Reference< 
XDocumentProperties >
     }
 
     pAppProps->endElement( XML_Properties );
+
+    pAppProps->endDocument();
 }
 
 static void
@@ -939,6 +943,8 @@ writeCustomProperties( XmlFilterBase& rSelf, const 
Reference< XDocumentPropertie
         ++nIndex;
     }
     pAppProps->endElement( XML_Properties );
+
+    pAppProps->endDocument();
 }
 
 void XmlFilterBase::exportDocumentProperties( const Reference< 
XDocumentProperties >& xProperties, bool bSecurityOptOpenReadOnly )
diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index 11c4557c75c4..a4fe4ec0d243 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -875,6 +875,8 @@ void ChartExport::WriteChartObj( const Reference< XShape >& 
xShape, sal_Int32 nI
 
     SetFS( pChart );
     ExportContent();
+    SetFS( pFS );
+    pChart->endDocument();
 }
 
 void ChartExport::InitRangeSegmentationProperties( const Reference< 
chart2::XChartDocument > & xChartDoc )
@@ -1116,6 +1118,7 @@ void ChartExport::exportAdditionalShapes( const 
Reference< css::chart::XChartDoc
                 pDrawing->endElement(FSNS(XML_cdr, XML_relSizeAnchor));
             }
             pDrawing->endElement(FSNS(XML_c, XML_userShapes));
+            pDrawing->endDocument();
         }
     }
     catch (const uno::Exception&)
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index 7cbd3c36abc1..fbf7f0672709 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/log.hxx>
 #include <sax/fshelper.hxx>
 #include "fastserializer.hxx"
 
@@ -29,12 +30,27 @@ FastSerializerHelper::FastSerializerHelper(const Reference< 
io::XOutputStream >&
     mpSerializer(new FastSaxSerializer(xOutputStream))
 {
     if( bWriteHeader )
-        mpSerializer->startDocument();
+        startDocument();
+}
+
+void FastSerializerHelper::startDocument()
+{
+    mpSerializer->startDocument();
+}
+
+void FastSerializerHelper::endDocument()
+{
+    std::unique_ptr<FastSaxSerializer> xSerializer(std::move(mpSerializer));
+    xSerializer->endDocument();
 }
 
 FastSerializerHelper::~FastSerializerHelper()
 {
-    mpSerializer->endDocument();
+    if (mpSerializer)
+    {
+        assert(false && "call endDocument explicitly before dtor to avoid 
potential exceptions during dtor");
+        endDocument();
+    }
 }
 
 void FastSerializerHelper::startElement(sal_Int32 elementTokenId)
diff --git a/sc/source/filter/excel/xestream.cxx 
b/sc/source/filter/excel/xestream.cxx
index c201af071c21..559808cd2a91 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -1120,6 +1120,12 @@ bool XclExpXmlStream::exportDocument()
 
     PopStream();
     // Free all FSHelperPtr, to flush data before committing storage
+    for (auto& entry : maOpenedStreamMap)
+    {
+        if (!entry.second.second)
+            continue;
+        entry.second.second->endDocument();
+    }
     maOpenedStreamMap.clear();
 
     commitStorage();
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx 
b/sd/source/filter/eppt/pptx-epptooxml.cxx
index a38fd1ba7a1d..41f9d1e90438 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -498,8 +498,15 @@ bool PowerPointExport::exportDocument()
     WriteModifyVerifier();
 
     mPresentationFS->endElementNS(XML_p, XML_presentation);
+    mPresentationFS->endDocument();
     mPresentationFS.reset();
     // Free all FSHelperPtr, to flush data before committing storage
+    for (auto& serializer : mpSlidesFSArray)
+    {
+        if (!serializer)
+            continue;
+        serializer->endDocument();
+    }
     mpSlidesFSArray.clear();
 
     commitStorage();
@@ -1085,6 +1092,8 @@ void PowerPointExport::WriteAuthors()
     }
 
     pFS->endElementNS(XML_p, XML_cmAuthorLst);
+
+    pFS->endDocument();
 }
 
 sal_Int32 PowerPointExport::GetAuthorIdAndLastIndex(const OUString& sAuthor, 
sal_Int32& nLastIndex)
@@ -1176,6 +1185,8 @@ void PowerPointExport::WritePresentationProps()
     pFS->endElementNS(XML_p, XML_showPr);
 
     pFS->endElementNS(XML_p, XML_presentationPr);
+
+    pFS->endDocument();
 }
 
 bool PowerPointExport::WriteComments(sal_uInt32 nPageNum)
@@ -1227,6 +1238,8 @@ bool PowerPointExport::WriteComments(sal_uInt32 nPageNum)
 
             pFS->endElementNS(XML_p, XML_cmLst);
 
+            pFS->endDocument();
+
             return true;
         }
     }
@@ -1452,6 +1465,8 @@ void PowerPointExport::ImplWriteNotes(sal_uInt32 nPageNum)
                 u"../notesMasters/notesMaster1.xml");
 
     SAL_INFO("sd.eppt", "-----------------");
+
+    pFS->endDocument();
 }
 
 void PowerPointExport::AddLayoutIdAndRelation(const FSHelperPtr& pFS, 
sal_Int32 nLayoutFileId)
@@ -1552,6 +1567,8 @@ void PowerPointExport::ImplWriteSlideMaster(sal_uInt32 
nPageNum, Reference< XPro
     pFS->endElementNS(XML_p, XML_sldMaster);
 
     SAL_INFO("sd.eppt", "----------------");
+
+    pFS->endDocument();
 }
 
 sal_Int32 PowerPointExport::GetLayoutFileId(sal_Int32 nOffset, sal_uInt32 
nMasterNum)
@@ -1621,6 +1638,8 @@ void PowerPointExport::ImplWritePPTXLayout(sal_Int32 
nOffset, sal_uInt32 nMaster
     mnLayoutFileIdMax ++;
 
     xDrawPages->remove(xSlide);
+
+    pFS->endDocument();
 }
 
 void PowerPointExport::WriteShapeTree(const FSHelperPtr& pFS, PageType 
ePageType, bool bMaster)
@@ -2292,6 +2311,8 @@ void PowerPointExport::WriteTheme(sal_Int32 nThemeNum, 
svx::Theme* pTheme)
 
     pFS->endElementNS(XML_a, XML_themeElements);
     pFS->endElementNS(XML_a, XML_theme);
+
+    pFS->endDocument();
 }
 
 bool PowerPointExport::ImplCreateDocument()
@@ -2370,6 +2391,8 @@ void PowerPointExport::WriteNotesMaster()
     pFS->endElementNS(XML_p, XML_notesMaster);
 
     SAL_INFO("sd.eppt", "----------------");
+
+    pFS->endDocument();
 }
 
 void PowerPointExport::embedEffectAudio(const FSHelperPtr& pFS, const 
OUString& sUrl, OUString& sRelId, OUString& sName)
diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index d5bc243d5c2e..3d2ea628b594 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -393,6 +393,7 @@ OString DocxExport::OutputChart( uno::Reference< 
frame::XModel > const & xModel,
         // tdf#134973: the model could get modified: e.g., calling 
XChartDocument::getSubTitle(),
         // which creates the object if absent, and sets the modified state.
         xModifiable->setModified(bOldModified);
+    pChartFS->endDocument();
     return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
 }
 
@@ -489,6 +490,8 @@ std::pair<OString, OString> 
DocxExport::WriteActiveXObject(const uno::Reference<
                                                               
sXMLFileName.subView(sBinaryFileName.indexOf("/") + 1)),
                                        RTL_TEXTENCODING_UTF8);
 
+    pActiveXFS->endDocument();
+
     return std::pair<OString, OString>(sXMLId, sName);
 }
 
@@ -664,6 +667,8 @@ void DocxExport::InitStyles()
 
     // switch the serializer back
     m_pAttrOutput->SetSerializer( m_pDocumentFS );
+
+    pStylesFS->endDocument();
 }
 
 void DocxExport::WriteFootnotesEndnotes()
@@ -693,6 +698,8 @@ void DocxExport::WriteFootnotesEndnotes()
         m_pVMLExport->SetFS(m_pDocumentFS);
         m_pSdrExport->setSerializer( m_pDocumentFS );
         m_pAttrOutput->SetSerializer( m_pDocumentFS );
+
+        pFootnotesFS->endDocument();
     }
 
     if ( !m_pAttrOutput->HasEndnotes() )
@@ -721,6 +728,8 @@ void DocxExport::WriteFootnotesEndnotes()
     m_pVMLExport->SetFS(m_pDocumentFS);
     m_pSdrExport->setSerializer( m_pDocumentFS );
     m_pAttrOutput->SetSerializer( m_pDocumentFS );
+
+    pEndnotesFS->endDocument();
 }
 
 void DocxExport::WritePostitFields()
@@ -741,6 +750,7 @@ void DocxExport::WritePostitFields()
     const auto eHasResolved = m_pAttrOutput->WritePostitFields();
     m_pAttrOutput->SetSerializer( m_pDocumentFS );
     pPostitFS->endElementNS( XML_w, XML_comments );
+    pPostitFS->endDocument();
 
     if (eHasResolved != DocxAttributeOutput::hasResolved::yes)
         return;
@@ -761,6 +771,7 @@ void DocxExport::WritePostitFields()
     m_pAttrOutput->WritePostItFieldsResolved();
     m_pAttrOutput->SetSerializer(m_pDocumentFS);
     pPostitFS->endElementNS(XML_w15, XML_commentsEx);
+    pPostitFS->endDocument();
 }
 
 void DocxExport::WriteNumbering()
@@ -799,6 +810,8 @@ void DocxExport::WriteNumbering()
     // switch the serializer back
     m_pDrawingML->SetFS( m_pDocumentFS );
     m_pAttrOutput->SetSerializer( m_pDocumentFS );
+
+    pNumberingFS->endDocument();
 }
 
 void DocxExport::WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, 
const char* pType )
@@ -871,6 +884,8 @@ void DocxExport::WriteHeaderFooter( const SwFormat* 
pFormat, bool bHeader, const
     m_pDocumentFS->singleElementNS( XML_w, nReference,
             FSNS( XML_w, XML_type ), pType,
             FSNS( XML_r, XML_id ), aRelId );
+
+    pFS->endDocument();
 }
 
 void DocxExport::WriteFonts()
@@ -897,6 +912,8 @@ void DocxExport::WriteFonts()
     m_pAttrOutput->SetSerializer( m_pDocumentFS );
 
     pFS->endElementNS( XML_w, XML_fonts );
+
+    pFS->endDocument();
 }
 
 void DocxExport::WriteProperties( )
@@ -1418,6 +1435,8 @@ void DocxExport::WriteSettings()
 
     // finish settings.xml
     pFS->endElementNS( XML_w, XML_settings );
+
+    pFS->endDocument();
 }
 
 void DocxExport::WriteTheme()
@@ -2107,6 +2126,7 @@ DocxExport::DocxExport(DocxExportFilter& rFilter, SwDoc& 
rDocument,
 
 DocxExport::~DocxExport()
 {
+    m_pDocumentFS->endDocument();
 }
 
 DocxSettingsData::DocxSettingsData()
commit 9b1467657cdc3f909056ed01f953a9e0372da07f
Author:     Caolán McNamara <[email protected]>
AuthorDate: Tue Oct 11 10:16:08 2022 +0100
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Jan 16 01:54:46 2023 +0000

    use std::unique_ptr
    
    Change-Id: Ibb3d71c8d50e1ad7236a6fe01ff83d3cd1a866f3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141214
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>
    (cherry picked from commit 2241ce64b29e87e0c654ab529b71aa98f71b4a14)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145545
    Tested-by: Tomaž Vajngerl <[email protected]>
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx
index 79f0e1a0f30f..115a3f912ca5 100644
--- a/include/sax/fshelper.hxx
+++ b/include/sax/fshelper.hxx
@@ -156,7 +156,7 @@ private:
     void pushAttributeValue( sal_Int32 attribute, const char* value );
     void pushAttributeValue( sal_Int32 attribute, const OString& value );
 
-    FastSaxSerializer* mpSerializer;
+    std::unique_ptr<FastSaxSerializer> mpSerializer;
 };
 
 typedef std::shared_ptr< FastSerializerHelper > FSHelperPtr;
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index a560e5bd1bad..7cbd3c36abc1 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -35,7 +35,6 @@ FastSerializerHelper::FastSerializerHelper(const Reference< 
io::XOutputStream >&
 FastSerializerHelper::~FastSerializerHelper()
 {
     mpSerializer->endDocument();
-    delete mpSerializer;
 }
 
 void FastSerializerHelper::startElement(sal_Int32 elementTokenId)

Reply via email to