[Boost-bugs] [Boost C++ Libraries] #8079: Chrono memory leak

Subject: [Boost-bugs] [Boost C++ Libraries] #8079: Chrono memory leak
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-16 15:45:57


#8079: Chrono memory leak
---------------------------------------------+------------------------------
 Reporter: dm413-boost@… | Owner: viboes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: chrono
  Version: Boost 1.53.0 | Severity: Problem
 Keywords: |
---------------------------------------------+------------------------------
 The constructor for duration_units_default_initializer_t (in
 chrono/io/duration_units.hpp) allocates two string_type arrays from the
 heap but never deletes them. The Visual C++ MFC debugger reports this as a
 memory leak (and I expect most other leak detectors will as well).

 These variables are class static and only one instance of this class (per
 CharT) is allocated anyway, so this is not a "serious" memory leak, but
 any memory leak reported by a leak detector is worth fixing to avoid
 masking other more serious memory leaks.

 I suggest adding a destructor similar to this:

 {{{
         ~duration_units_default_initializer_t()
           {
             if (duration_units_default_holder<CharT>::initialized_)
             {
               delete[]
 duration_units_default_holder<CharT>::n_d_valid_units_;
               duration_units_default_holder<CharT>::n_d_valid_units_ = 0;
               delete[] duration_units_default_holder<CharT>::valid_units_;
               duration_units_default_holder<CharT>::valid_units_ = 0;
               duration_units_default_holder<CharT>::initialized_ = false;
             }
           }
 }}}

 Further suggestions for this code:

 1. Make the class static member variables n_d_valid_units_ and
 valid_units_ into non-static member variables. Only one object of this
 type is created, so making them them regular member variables makes things
 clearer and simplifies the code.

 2. Do away with the initialized_ member variable entirely. If you make the
 other member variables non-static, there is no need for this variable.

 3. If I am wrong and it is possible to create more than one instance of
 duration_units_default_initializer_t<CharT>, then you will need to make
 the destructor more intelligent and use smart pointers or a reference
 count to know when to destroy the static member variables.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8079>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC