]> git.lyx.org Git - features.git/commitdiff
Fix memory leak and assignment operator signature
authorGeorg Baum <baum@lyx.org>
Tue, 1 Jul 2014 20:13:54 +0000 (22:13 +0200)
committerGeorg Baum <baum@lyx.org>
Tue, 1 Jul 2014 20:17:07 +0000 (22:17 +0200)
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
src/support/unicode.h

index 343b8def2be42438ad449c085e59a8af3e5fb170..954aa79322b5e7d509a4ea6195480494d0fa152e 100644 (file)
@@ -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;
 }
 
 
index ddcd6c8fd07e5ade79d3c109be115c3105799230..87a8392158a232c2f6a5814ed21ffa040be8f704 100644 (file)
@@ -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();