Fixed issue #65 pmr::monotonic_buffer_resource::allocate() can return a pointer to freed memory after release() is called.

This commit is contained in:
Ion Gaztañaga
2018-01-27 21:23:43 +01:00
parent feeafbe9f3
commit 22f00f45d8
3 changed files with 22 additions and 10 deletions

View File

@ -61,8 +61,8 @@ In short, what does [*Boost.Container] offer?
There is no need to compile [*Boost.Container], since it's a header-only library, There is no need to compile [*Boost.Container], since it's a header-only library,
just include your Boost header directory in your compiler include path *except if you use*: just include your Boost header directory in your compiler include path *except if you use*:
* [link container.extended_functionality.extended_allocators Extended Allocators] * [link container.extended_allocators Extended Allocators]
* Some [link container.extended_functionality.polymorphic_memory_resources Polymorphic Memory Resources] classes. * Some [link container.polymorphic_memory_resources Polymorphic Memory Resources] classes.
Those exceptions are are implemented as a separately compiled library, so in those cases you must install binaries Those exceptions are are implemented as a separately compiled library, so in those cases you must install binaries
in a location that can be found by your linker. in a location that can be found by your linker.
@ -322,7 +322,7 @@ can a stable design approach the behavior of `vector` (random access iterators,
insertion/deletion, minimal memory overhead, etc.)? insertion/deletion, minimal memory overhead, etc.)?
The following image describes the layout of a possible data structure upon which to base the design of a stable vector: The following image describes the layout of a possible data structure upon which to base the design of a stable vector:
[$../../libs/container/doc/html/images/stable_vector.png [width 50%] [align center] ] [$../../libs/container/doc/images/stable_vector.png [width 50%] [align center] ]
Each element is stored in its own separate node. All the nodes are referenced from a contiguous array of pointers, but Each element is stored in its own separate node. All the nodes are referenced from a contiguous array of pointers, but
also every node contains an "up" pointer referring back to the associated array cell. This up pointer is the key element also every node contains an "up" pointer referring back to the associated array cell. This up pointer is the key element
@ -1005,7 +1005,7 @@ members.
This strong exception guarantee also precludes the possibility of using some type of This strong exception guarantee also precludes the possibility of using some type of
in-place reallocations that can further improve the insertion performance of `vector` See in-place reallocations that can further improve the insertion performance of `vector` See
[link container.extended_functionality.extended_allocators Extended Allocators] to know more [link container.extended_allocators Extended Allocators] to know more
about these optimizations. about these optimizations.
[classref boost::container::vector vector] always uses move constructors/assignments [classref boost::container::vector vector] always uses move constructors/assignments
@ -1244,6 +1244,13 @@ use [*Boost.Container]? There are several reasons for that:
[endsect] [endsect]
[section:release_notes_boost_1_67_00 Boost 1.67 Release]
* Fixed bugs:
* [@https://github.com/boostorg/container/issues/58 GitHub #65: ['"`pmr::monotonic_buffer_resource::allocate()` can return a pointer to freed memory after `release()` is called"]].
[endsect]
[section:release_notes_boost_1_66_00 Boost 1.66 Release] [section:release_notes_boost_1_66_00 Boost 1.66 Release]
* ['flat_[multi]map/set] can now work as container adaptors, as proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0429r1.pdf P0429R1]. * ['flat_[multi]map/set] can now work as container adaptors, as proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0429r1.pdf P0429R1].
@ -1334,7 +1341,7 @@ use [*Boost.Container]? There are several reasons for that:
[section:release_notes_boost_1_60_00 Boost 1.60 Release] [section:release_notes_boost_1_60_00 Boost 1.60 Release]
* Implemented [link container.extended_functionality.polymorphic_memory_resources Polymorphic Memory Resources]. * Implemented [link container.polymorphic_memory_resources Polymorphic Memory Resources].
* Add more BOOST_ASSERT checks to test preconditions in some operations (like `pop_back`, `pop_front`, `back`, `front`, etc.) * Add more BOOST_ASSERT checks to test preconditions in some operations (like `pop_back`, `pop_front`, `back`, `front`, etc.)
* Added C++11 `back`/`front` operations to [classref boost::container::basic_string basic_string]. * Added C++11 `back`/`front` operations to [classref boost::container::basic_string basic_string].
* Fixed bugs: * Fixed bugs:
@ -1392,9 +1399,9 @@ use [*Boost.Container]? There are several reasons for that:
[section:release_notes_boost_1_56_00 Boost 1.56 Release] [section:release_notes_boost_1_56_00 Boost 1.56 Release]
* Added DlMalloc-based [link container.extended_functionality.extended_allocators Extended Allocators]. * Added DlMalloc-based [link container.extended_allocators Extended Allocators].
* [link container.extended_functionality.configurable_containers.configurable_tree_based_associative_containers Improved configurability] * [link container.configurable_containers.configurable_tree_based_associative_containers Improved configurability]
of tree-based ordered associative containers. AVL, Scapegoat and Splay trees are now available of tree-based ordered associative containers. AVL, Scapegoat and Splay trees are now available
to implement [classref boost::container::set set], [classref boost::container::multiset multiset], to implement [classref boost::container::set set], [classref boost::container::multiset multiset],
[classref boost::container::map map] and [classref boost::container::multimap multimap]. [classref boost::container::map map] and [classref boost::container::multimap multimap].

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -60,14 +60,14 @@ void monotonic_buffer_resource::increase_next_buffer_at_least_to(std::size_t min
monotonic_buffer_resource::monotonic_buffer_resource(memory_resource* upstream) BOOST_NOEXCEPT monotonic_buffer_resource::monotonic_buffer_resource(memory_resource* upstream) BOOST_NOEXCEPT
: m_memory_blocks(upstream ? *upstream : *get_default_resource()) : m_memory_blocks(upstream ? *upstream : *get_default_resource())
, m_current_buffer(0u) , m_current_buffer(0)
, m_current_buffer_size(0u) , m_current_buffer_size(0u)
, m_next_buffer_size(initial_next_buffer_size) , m_next_buffer_size(initial_next_buffer_size)
{} {}
monotonic_buffer_resource::monotonic_buffer_resource(std::size_t initial_size, memory_resource* upstream) BOOST_NOEXCEPT monotonic_buffer_resource::monotonic_buffer_resource(std::size_t initial_size, memory_resource* upstream) BOOST_NOEXCEPT
: m_memory_blocks(upstream ? *upstream : *get_default_resource()) : m_memory_blocks(upstream ? *upstream : *get_default_resource())
, m_current_buffer(0u) , m_current_buffer(0)
, m_current_buffer_size(0u) , m_current_buffer_size(0u)
, m_next_buffer_size(minimum_buffer_size) , m_next_buffer_size(minimum_buffer_size)
{ //In case initial_size is zero { //In case initial_size is zero
@ -87,7 +87,12 @@ monotonic_buffer_resource::~monotonic_buffer_resource()
{ this->release(); } { this->release(); }
void monotonic_buffer_resource::release() BOOST_NOEXCEPT void monotonic_buffer_resource::release() BOOST_NOEXCEPT
{ m_memory_blocks.release(); } {
m_memory_blocks.release();
m_current_buffer = 0u;
m_current_buffer_size = 0u;
m_next_buffer_size = initial_next_buffer_size;
}
memory_resource* monotonic_buffer_resource::upstream_resource() const BOOST_NOEXCEPT memory_resource* monotonic_buffer_resource::upstream_resource() const BOOST_NOEXCEPT
{ return &m_memory_blocks.upstream_resource(); } { return &m_memory_blocks.upstream_resource(); }