From 0e8fea07057fe603d6967e8be9b76887f7b318ec Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 1 Jul 2014 22:13:54 +0200 Subject: [PATCH] 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. --- src/support/unicode.cpp | 9 ++++++--- src/support/unicode.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) 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(); -- 2.39.5