Skip to content

Buffer overflow with memory_pool_collection #99

@athanase

Description

@athanase

Hello,

memory_pool_collection reports a buffer overflow on deallocation. I might be doing something wrong...

Here is the code that fails on my machine (linux x64)

int32_t main( int32_t argc, char* argv[] )
{
	namespace memory = foonathan::memory;
	using namespace memory::literals;

	using pools = memory::memory_pool_collection< memory::node_pool,
						      memory::identity_buckets,
						      memory::allocator_reference< memory::malloc_allocator > >;

	const auto max_size = 64u;
	pools pool( max_size, 200_MiB, memory::malloc_allocator{} );

	memory::vector< int32_t, decltype( pool ) > vec( { 1, 2, 3, 4 }, pool );
	return 0;
}

the output of the program:

/home/test/build/debug/bin/sandbox
[foonathan::memory] Buffer overflow at address 0x7f0863cf65b8 detected, corresponding memory block 0x7f0863cf65a0 has only size 16.Signal: SIGABRT (Aborted)

the stacktrace:

raise 0x00007f08919e9615
abort 0x00007f08919d2862
(anonymous namespace)::default_buffer_overflow_handler debugging.cpp:95
foonathan::memory::detail::debug_fill_free debug_helpers.cpp:69
foonathan::memory::detail::free_memory_list::deallocate free_list.cpp:219
foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> >::deallocate_array memory_pool_collection.hpp:238
foonathan::memory::allocator_traits<foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > >::deallocate_array memory_pool_collection.hpp:451
foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > >, foonathan::memory::no_mutex>::deallocate_array allocator_storage.hpp:201
foonathan::memory::std_allocator<int, foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > >::deallocate_impl std_allocator.hpp:275
foonathan::memory::std_allocator<int, foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > >::deallocate std_allocator.hpp:203
std::allocator_traits<foonathan::memory::std_allocator<int, foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > > >::deallocate alloc_traits.h:341
std::_Vector_base<int, foonathan::memory::std_allocator<int, foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > > >::_M_deallocate stl_vector.h:354
std::_Vector_base<int, foonathan::memory::std_allocator<int, foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > > >::~_Vector_base stl_vector.h:335
std::vector<int, foonathan::memory::std_allocator<int, foonathan::memory::memory_pool_collection<foonathan::memory::node_pool, foonathan::memory::identity_buckets, foonathan::memory::allocator_storage<foonathan::memory::reference_storage<foonathan::memory::detail::lowlevel_allocator<foonathan::memory::detail::malloc_allocator_impl> >, foonathan::memory::no_mutex> > > >::~vector stl_vector.h:683
main main.cpp:67
__libc_start_main 0x00007f08919d4152
_start free_list_array.hpp:98

and the memory content:

image

Thanks in advance for the help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions