From: Georg Baum Date: Tue, 1 Jul 2014 20:13:54 +0000 (+0200) Subject: Fix memory leak and assignment operator signature X-Git-Tag: 2.2.0alpha1~1814 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0e8fea07057fe603d6967e8be9b76887f7b318ec;p=features.git 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. --- diff --git a/src/support/unicode.cpp b/src/support/unicode.cpp index 343b8def2b..954aa79322 100644 --- a/src/support/unicode.cpp +++ b/src/support/unicode.cpp @@ -61,7 +61,7 @@ struct IconvProcessor::Impl ~Impl() { 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; @@ -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_); + } + return *this; } diff --git a/src/support/unicode.h b/src/support/unicode.h index ddcd6c8fd0..87a8392158 100644 --- a/src/support/unicode.h +++ b/src/support/unicode.h @@ -49,7 +49,7 @@ public: /// copy constructor needed because of pimpl_ IconvProcessor(IconvProcessor const &); /// assignment operator needed because of pimpl_ - void operator=(IconvProcessor const &); + IconvProcessor & operator=(IconvProcessor const &); /// destructor ~IconvProcessor();