[Botan-devel] [PATCH] Bug in Pooling_Allocator::allocate()

Matthew Gregan kinetik at orcon.net.nz
Fri Nov 25 22:18:09 EST 2005


Hello,

Please find attached a small patch for a bug I ran into recently.

Botan's Pooling_Allocator assumes that Buffers stored in free_list are
sorted, and uses std::inplace_merge() in deallocate() to ensure that each
freed Buffer is positioned in free_list in order.  The same check was not
being performed when a Buffer was added to free_list in allocate().

Cheers,
-mjg
-- 
Matthew Gregan                     |/
                                  /|                kinetik at orcon.net.nz
-------------- next part --------------
# 
# 
# patch "botan/mem_pool.cpp"
#  from [3b09bd3c3d6fdf3aa854529239e9d4e4d8ac18f5]
#    to [54ee4313712d9f47ad38cdfc5ad00d890d607de5]
# 
============================================================
--- botan/mem_pool.cpp	3b09bd3c3d6fdf3aa854529239e9d4e4d8ac18f5
+++ botan/mem_pool.cpp	54ee4313712d9f47ad38cdfc5ad00d890d607de5
@@ -159,6 +159,9 @@
    if(!block.buf)
       throw Memory_Exhaustion();
    free_list.push_back(block);
+   if(free_list.size() >= 2)
+      std::inplace_merge(free_list.begin(), free_list.end() - 1,
+                         free_list.end());
 
    new_buf = find_free_block(n);
    if(new_buf)


More information about the botan-devel mailing list