diff --git a/test/monotonic_buffer_resource_test.cpp b/test/monotonic_buffer_resource_test.cpp index 82e7e54..2f3f0b1 100644 --- a/test/monotonic_buffer_resource_test.cpp +++ b/test/monotonic_buffer_resource_test.cpp @@ -230,6 +230,9 @@ struct derived_from_monotonic_buffer_resource void test_upstream_resource() { + //Allocate buffer first to avoid stack-use-after-scope in monotonic_buffer_resource's destructor + const std::size_t BufSz = monotonic_buffer_resource::initial_next_buffer_size; + boost::move_detail::aligned_storage::type buf; //Test stores the resource and uses it to allocate memory derived_from_memory_resource dmr; dmr.reset(); @@ -240,10 +243,8 @@ void test_upstream_resource() BOOST_TEST(dmbr.current_buffer() == 0); //Test it does not allocate any memory BOOST_TEST(dmr.do_allocate_called == false); - const std::size_t BufSz = monotonic_buffer_resource::initial_next_buffer_size; - //Now allocate storage, and stub it as the return buffer + //Now stub buffer storage it as the return buffer //for "derived_from_memory_resource": - boost::move_detail::aligned_storage::type buf; dmr.do_allocate_return = &buf; //Test that allocation uses the upstream_resource() void *addr = dmbr.do_allocate(1u, 1u);