Opened 9 years ago
Closed 9 years ago
#9166 closed Bugs (fixed)
Memory leak when copying empty boost::container::vector
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | container |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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
Attachments (1)
Change History (3)
by , 9 years ago
Attachment: | container_leak.patch added |
---|
comment:1 by , 9 years ago
Summary: | Memory when copying empty boost::container::vector → Memory leak when copying empty boost::container::vector |
---|
comment:2 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch that disables allocation when space for 0 elements is needed.