From 4fe154d6e068aa9accdb64e8ebd4d1491b6c94f9 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 11 Dec 2017 15:19:18 +0000 Subject: ensure dec ref if exception called MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7aabfd98e89389e15bf7b78abb81d3385fe30342 Reviewed-on: https://gerrit.libreoffice.org/46245 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- svtools/source/svhtml/parhtml.cxx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'svtools/source/svhtml') diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx index ec8f7f5db683..9e5974ae5d40 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -237,6 +237,27 @@ HTMLParser::~HTMLParser() { } +namespace +{ + class RefGuard + { + private: + HTMLParser& m_rParser; + public: + RefGuard(HTMLParser& rParser) + : m_rParser(rParser) + { + m_rParser.AddFirstRef(); + } + + ~RefGuard() + { + if (m_rParser.GetStatus() != SvParserState::Pending) + m_rParser.ReleaseRef(); // Parser not needed anymore + } + }; +} + SvParserState HTMLParser::CallParser() { eState = SvParserState::Working; @@ -246,10 +267,9 @@ SvParserState HTMLParser::CallParser() nPre_LinePos = 0; bPre_IgnoreNewPara = false; - AddFirstRef(); + RefGuard aRefGuard(*this); + Continue( HtmlTokenId::NONE ); - if( SvParserState::Pending != eState ) - ReleaseRef(); // Parser not needed anymore return eState; } -- cgit