[Boost-bugs] [Boost C++ Libraries] #9166: Memory when copying empty boost::container::vector

Subject: [Boost-bugs] [Boost C++ Libraries] #9166: Memory when copying empty boost::container::vector
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-09-26 14:55:22


#9166: Memory when copying empty boost::container::vector
------------------------------+------------------------
 Reporter: onlyone@… | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: container
  Version: Boost 1.54.0 | Severity: Problem
 Keywords: |
------------------------------+------------------------
 Consider the following simple program:

 {{{
 #include <boost/container/vector.hpp>

 int main() {
     while (true) {
         boost::container::vector<int> vec;
         boost::container::vector<int> vec2(vec);
     }
 }
 }}}

 With Boost 1.54.0, this leaks an unbounded amount of memory. The copy
 contructor of `boost::container::vector` performs an allocation (which in
 this case asks for 0 bytes), and sets the capacity of the new vector the
 size of this allocation (0 elements), and since the capacity is 0, the
 destructor of vec2 does not deallocate this memory.

 A simple patch is attached which disables allocation when the requested
 size is 0. This may not be the optimal solution (for example, there might
 be code that subsequently reads from `m_start` and expects it to contain a
 valid value (I have not yet studied the code sufficiently to know)). Even
 so, this is a major issue, and so I am reporting it even without a fully
 tested patch.

 Evan Wallace

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9166>
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:14 UTC