Fix memory leak and assignment operator signature

The IconvProcessor assignment operator did not delete pimpl_ and used a
non-standard signature. If you want to know why the standard signature is
important, read "Effective C++" by Scott Meyers.
This commit is contained in:
Georg Baum 2014-07-01 22:13:54 +02:00
parent c2de96d2ed
commit 0e8fea0705
2 changed files with 7 additions and 4 deletions

View File

@ -61,7 +61,7 @@ struct IconvProcessor::Impl
~Impl() ~Impl()
{ {
if (cd != invalid_cd && iconv_close(cd) == -1) if (cd != invalid_cd && iconv_close(cd) == -1)
LYXERR0("Error returned from iconv_close(" << errno << ")"); LYXERR0("Error returned from iconv_close(" << errno << ')');
} }
iconv_t cd; iconv_t cd;
@ -88,10 +88,13 @@ IconvProcessor::~IconvProcessor()
} }
void IconvProcessor::operator=(IconvProcessor const & other) IconvProcessor & IconvProcessor::operator=(IconvProcessor const & other)
{ {
if (&other != this) if (&other != this) {
delete pimpl_;
pimpl_ = new Impl(other.pimpl_->tocode_, other.pimpl_->fromcode_); pimpl_ = new Impl(other.pimpl_->tocode_, other.pimpl_->fromcode_);
}
return *this;
} }

View File

@ -49,7 +49,7 @@ public:
/// copy constructor needed because of pimpl_ /// copy constructor needed because of pimpl_
IconvProcessor(IconvProcessor const &); IconvProcessor(IconvProcessor const &);
/// assignment operator needed because of pimpl_ /// assignment operator needed because of pimpl_
void operator=(IconvProcessor const &); IconvProcessor & operator=(IconvProcessor const &);
/// destructor /// destructor
~IconvProcessor(); ~IconvProcessor();