[Libreoffice-commits] core.git: sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Nov 28 04:53:02 PST 2013


 sw/qa/core/data/rtf/pass/abi2128.rtf           |   17 +++++++++++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   11 ++++++++++-
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    3 +++
 3 files changed, 30 insertions(+), 1 deletion(-)

New commits:
commit f7ef84640258e4ee6ddc4cc5cbf58a2d89860afa
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Nov 28 13:35:27 2013 +0100

    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.
    
    Change-Id: Idfa040bf3026a9515a120cd7afaf7d314553a131

diff --git a/sw/qa/core/data/rtf/pass/abi2128.rtf b/sw/qa/core/data/rtf/pass/abi2128.rtf
new file mode 100644
index 0000000..270c675
--- /dev/null
+++ b/sw/qa/core/data/rtf/pass/abi2128.rtf
@@ -0,0 +1,17 @@
+{\rtf1\ansi\ansicpg1252\deff0
+{\fonttbl
+{\f0\froman\fcharset0\fprq2\fttruetype Times New Roman;}}
+{\colortbl
+\red0\green0\blue0;
+\red255\green255\blue255;}
+{\stylesheet
+{\s2\sl240\slmult1\sbasedon1 Normal Clean;}
+{\s1\sl240\slmult1\f0\fs24 Normal;}}
+\kerning0\cf0\viewkind1\paperw12240\paperh15840\margl1440\margr1440\widowctl
+\sectd\sbknone\colsx360\headery0\footery0
+\pard\qj\sl240\slmult1{\f0\fs24\lang1033{\*\listtag0}the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan. the big green dog bit the little afgan.}
+{\header
+\par\pard\sl240\slmult1
+\par\pard\sl240\slmult1
+\par\pard\sl240\slmult1
+\par\pard\s2\sl240\slmult1{\f0\fs24\lang1033{\*\listtag0}Hi this is the header}}}
\ No newline at end of file
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index cd17d92..c30e943 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -253,6 +253,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     m_aSuperBuffer(),
     m_bHasFootnote(false),
     m_pSuperstream(0),
+    m_nStreamType(0),
     m_nHeaderFooterPositions(),
     m_nGroupStartPos(0),
     m_aBookmarks(),
@@ -314,6 +315,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;
@@ -350,6 +356,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())
     {
@@ -4510,7 +4517,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);
     }
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index a0b1076..eada5fa 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -313,6 +313,7 @@ namespace writerfilter {
                 Stream& Mapper();
                 void setSubstream(bool bIsSubtream);
                 void setSuperstream(RTFDocumentImpl *pSuperstream);
+                void setStreamType(Id nId);
                 void setAuthor(OUString& rAuthor);
                 void setAuthorInitials(OUString& rAuthorInitials);
                 void setIgnoreFirst(OUString& rIgnoreFirst);
@@ -413,6 +414,8 @@ namespace writerfilter {
                 bool m_bHasFootnote;
                 /// Superstream of this substream.
                 RTFDocumentImpl *m_pSuperstream;
+                /// Type of the stream: header, footer, footnote, etc.
+                Id m_nStreamType;
                 std::queue< std::pair<Id, sal_uInt32> > m_nHeaderFooterPositions;
                 sal_uInt32 m_nGroupStartPos;
                 /// Ignore the first occurrence of this text.


More information about the Libreoffice-commits mailing list