Skip to content
Snippets Groups Projects
Commit 614a8dfa authored by Markus Blatt's avatar Markus Blatt
Browse files

Added a sanity check during free when compiled without -DNDEBUG.

There might be liftime issues with the allocated memory when copying
a pool. Therefore I added a check whether the memory was actually
allocated by the pool when freeing it.
parent 06a10d44
No related branches found
No related tags found
No related merge requests found
......@@ -526,6 +526,18 @@ namespace Dune
inline void Pool<T,S>::free(void* b)
{
if(b) {
#ifndef NDEBUG
Chunk* current=chunks_;
while(current) {
std::cout<<"b: "<<b<<" start: "<<&current->chunk_<<" end:"<<(&current->chunk_)+chunkSize<<std::endl;
if(static_cast<void*>(&current->chunk_)<=b &&
static_cast<void*>((&current->chunk_)+chunkSize)>b)
break;
current=current->next_;
}
if(!current)
throw std::bad_alloc();
#endif
Reference* freed = static_cast<Reference*>(b);
freed->next_ = head_;
head_ = freed;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment