Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert in debug build when memory_pool alloc/dealloc in certain order #111

Closed
jwdevel opened this issue Apr 23, 2021 · 2 comments
Closed

Comments

@jwdevel
Copy link
Contributor

jwdevel commented Apr 23, 2021

Below is a simple test that fails for me on the debug build.
I get the error:

[foonathan::memory] Assertion failure in function allocate (.../foonathan-memory/src/detail/free_list.cpp:444): Assertion "last_dealloc_prev_ == prev" failed.

I am not sure if this is a genuine error that the debug build is detecting, or if it is an error introduced by the different behavior present in debug builds...

typedef foonathan::memory::memory_pool<> MyPool;
MyPool pool(100, 1024);
auto p1 = pool.allocate_node();
auto p2 = pool.allocate_node();
pool.deallocate_node(p1);
pool.deallocate_node(p2);

p1 = pool.allocate_node();
p2 = pool.allocate_node();  // <-- assertion happens here
pool.deallocate_node(p1);
pool.deallocate_node(p2);
@jwdevel
Copy link
Contributor Author

jwdevel commented Apr 23, 2021

Note: it passes on 'RelWithDeb', too.

@foonathan
Copy link
Owner

Thanks for catching that one! It seems this has been a bug for years, but as it only happens if you deallocate in the exact same order that you allocated (and most containers destroy in reverse order), nobody ran into it before, apparently.

I've expanded the tests as well: previously, they tested only one "random" ordering of allocations and deallocations, now they do same order and reverse order as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants