Kaydet (Commit) f5e2dbb4 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Avoid potential double-delete in ~XMLFile2UTFConverter

...as the implicitly defined copy operations would just copy the m_p* member
pointers.  Needed some modification of the ParserCleanup class so that Entity
(which has a XMLFile2UTFConverter member) can be std::move'd into
SaxExpatParser_Impl::pushEntity.

Found by new -Wdeprecated-copy of GCC trunk towards GCC 9.

Change-Id: I0cb5b5dbcd55249b475ed74b4ac6bcb12f20f2c6
Reviewed-on: https://gerrit.libreoffice.org/56453
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst d8733e2c
......@@ -20,6 +20,10 @@
#ifndef INCLUDED_SAX_INC_XML2UTF_HXX
#define INCLUDED_SAX_INC_XML2UTF_HXX
#include <sal/config.h>
#include <memory>
#include <sal/types.h>
namespace sax_expatwrap {
......@@ -73,13 +77,9 @@ class XMLFile2UTFConverter
{
public:
XMLFile2UTFConverter( ):
m_bStarted( false ),
m_pText2Unicode( nullptr ),
m_pUnicode2Text( nullptr )
m_bStarted( false )
{}
~XMLFile2UTFConverter();
void setInputStream( css::uno::Reference< css::io::XInputStream > const &r ) { m_in = r; }
void setEncoding( const OString &s ) { m_sEncoding = s; }
......@@ -116,8 +116,8 @@ private:
bool m_bStarted;
OString m_sEncoding;
Text2UnicodeConverter *m_pText2Unicode;
Unicode2TextConverter *m_pUnicode2Text;
std::unique_ptr<Text2UnicodeConverter> m_pText2Unicode;
std::unique_ptr<Unicode2TextConverter> m_pUnicode2Text;
};
}
......
......@@ -20,6 +20,7 @@
#include <string.h>
#include <cassert>
#include <memory>
#include <utility>
#include <vector>
......@@ -159,8 +160,8 @@ public: // module scope
// External entity stack
vector<struct Entity> vecEntity;
void pushEntity( const struct Entity &entity )
{ vecEntity.push_back( entity ); }
void pushEntity( Entity &&entity )
{ vecEntity.push_back( std::move(entity) ); }
void popEntity()
{ vecEntity.pop_back( ); }
struct Entity &getEntity()
......@@ -388,18 +389,18 @@ class ParserCleanup
{
private:
SaxExpatParser_Impl& m_rParser;
Entity& m_rEntity;
XML_Parser m_xmlParser;
public:
ParserCleanup(SaxExpatParser_Impl& rParser, Entity& rEntity)
ParserCleanup(SaxExpatParser_Impl& rParser, XML_Parser xmlParser)
: m_rParser(rParser)
, m_rEntity(rEntity)
, m_xmlParser(xmlParser)
{
}
~ParserCleanup()
{
m_rParser.popEntity();
//XML_ParserFree accepts a null arg
XML_ParserFree(m_rEntity.pParser);
XML_ParserFree(m_xmlParser);
}
};
......@@ -469,9 +470,10 @@ void SaxExpatParser::parseStream( const InputSource& structSource)
m_pImpl->exception = SAXParseException();
m_pImpl->pushEntity( entity );
auto const xmlParser = entity.pParser;
m_pImpl->pushEntity( std::move(entity) );
ParserCleanup aEnsureFree(*m_pImpl, entity);
ParserCleanup aEnsureFree(*m_pImpl, xmlParser);
// start the document
if( m_pImpl->rDocumentHandler.is() ) {
......@@ -847,7 +849,8 @@ bool SaxExpatParser_Impl::callbackExternalEntityRef(
}
entity.converter.setInputStream( entity.structSource.aInputStream );
pImpl->pushEntity( entity );
auto const xmlParser = entity.pParser;
pImpl->pushEntity( std::move(entity) );
try
{
pImpl->parse();
......@@ -870,7 +873,7 @@ bool SaxExpatParser_Impl::callbackExternalEntityRef(
pImpl->popEntity();
XML_ParserFree( entity.pParser );
XML_ParserFree( xmlParser );
}
return bOK;
......
......@@ -22,6 +22,7 @@
#include <sal/types.h>
#include <o3tl/make_unique.hxx>
#include <rtl/textenc.h>
#include <rtl/tencinfo.h>
#include <com/sun/star/io/NotConnectedException.hpp>
......@@ -114,14 +115,6 @@ sal_Int32 XMLFile2UTFConverter::readAndConvert( Sequence<sal_Int8> &seq , sal_In
return nRead;
}
XMLFile2UTFConverter::~XMLFile2UTFConverter()
{
delete m_pText2Unicode;
delete m_pUnicode2Text;
}
void XMLFile2UTFConverter::removeEncoding( Sequence<sal_Int8> &seq )
{
const sal_Int8 *pSource = seq.getArray();
......@@ -331,8 +324,8 @@ void XMLFile2UTFConverter::initializeDecoding()
rtl_TextEncoding encoding = rtl_getTextEncodingFromMimeCharset( m_sEncoding.getStr() );
if( encoding != RTL_TEXTENCODING_UTF8 )
{
m_pText2Unicode = new Text2UnicodeConverter( m_sEncoding );
m_pUnicode2Text = new Unicode2TextConverter( RTL_TEXTENCODING_UTF8 );
m_pText2Unicode = o3tl::make_unique<Text2UnicodeConverter>( m_sEncoding );
m_pUnicode2Text = o3tl::make_unique<Unicode2TextConverter>( RTL_TEXTENCODING_UTF8 );
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment