Fix stack-use-after-scope error detected by ASAN in "test_upstream_resource".

This commit is contained in:
Ion Gaztañaga
2018-08-20 12:30:55 +02:00
parent 139db663a3
commit 84f6f27788

View File

@@ -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<BufSz+block_slist::header_size>::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<BufSz+block_slist::header_size>::type buf;
dmr.do_allocate_return = &buf;
//Test that allocation uses the upstream_resource()
void *addr = dmbr.do_allocate(1u, 1u);