From e7debed56f5f037208e49233034ad8a578d1dfbc Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 28 Nov 2013 13:35:27 +0100 Subject: fdo#66011 abi#2128 RTF import: fix memory leak Commit 9389cf78e304a5a99bcf1745b9388e14ac36281a (cp#1000018 RTF import: empty para at the end of footnote text got lost, 2013-11-15) assumed that \par at the end of all substreams means an empty paragraph, but it turns out this is only true for footnotes/endnotes, but not for e.g. headers. Additionally, that commit actually causes a memory leak, which is detected by an assert in the SwIndexReg dtor, so crash-testing caught this. (cherry picked from commit f7ef84640258e4ee6ddc4cc5cbf58a2d89860afa) Change-Id: Idfa040bf3026a9515a120cd7afaf7d314553a131 Reviewed-on: https://gerrit.libreoffice.org/7663 Reviewed-by: Markus Mohrhard Tested-by: Markus Mohrhard --- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'writerfilter/source/rtftok/rtfdocumentimpl.cxx') diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 72f2c8cc55d0..7f3e25353665 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -252,6 +252,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference const& x m_aSuperBuffer(), m_bHasFootnote(false), m_pSuperstream(0), + m_nStreamType(0), m_nHeaderFooterPositions(), m_nGroupStartPos(0), m_aBookmarks(), @@ -313,6 +314,11 @@ void RTFDocumentImpl::setSuperstream(RTFDocumentImpl *pSuperstream) m_pSuperstream = pSuperstream; } +void RTFDocumentImpl::setStreamType(Id nId) +{ + m_nStreamType = nId; +} + void RTFDocumentImpl::setAuthor(OUString& rAuthor) { m_aAuthor = rAuthor; @@ -349,6 +355,7 @@ void RTFDocumentImpl::resolveSubstream(sal_uInt32 nPos, Id nId, OUString& rIgnor // Seek to header position, parse, then seek back. RTFDocumentImpl::Pointer_t pImpl(new RTFDocumentImpl(m_xContext, m_xInputStream, m_xDstDoc, m_xFrame, m_xStatusIndicator)); pImpl->setSuperstream(this); + pImpl->setStreamType(nId); pImpl->setIgnoreFirst(rIgnoreFirst); if (!m_aAuthor.isEmpty()) { @@ -4523,7 +4530,9 @@ int RTFDocumentImpl::popState() // This is the end of the doc, see if we need to close the last section. if (m_pTokenizer->getGroup() == 1 && !m_bFirstRun) { - if (m_bNeedCr && !isSubstream()) + // \par means an empty paragraph at the end of footnotes/endnotes, but + // not in case of other substreams, like headers. + if (m_bNeedCr && !(m_nStreamType == NS_rtf::LN_footnote || m_nStreamType == NS_rtf::LN_endnote)) dispatchSymbol(RTF_PAR); sectBreak(true); } -- cgit v1.2.3