Index: boost/pool/simple_segregated_storage.hpp =================================================================== --- boost/pool/simple_segregated_storage.hpp (revision 53577) +++ boost/pool/simple_segregated_storage.hpp (working copy) @@ -147,7 +147,8 @@ void free_n(void * const chunks, const size_type n, const size_type partition_size) { - add_block(chunks, n * partition_size, partition_size); + if(n != 0) + add_block(chunks, n * partition_size, partition_size); } // pre: chunks was previously allocated from *this with the same @@ -156,7 +157,8 @@ void ordered_free_n(void * const chunks, const size_type n, const size_type partition_size) { - add_ordered_block(chunks, n * partition_size, partition_size); + if(n != 0) + add_ordered_block(chunks, n * partition_size, partition_size); } }; @@ -247,6 +249,8 @@ void * simple_segregated_storage::malloc_n(const size_type n, const size_type partition_size) { + if(n == 0) + return 0; void * start = &first; void * iter; do Index: libs/pool/test/test_pool_alloc.cpp =================================================================== --- libs/pool/test/test_pool_alloc.cpp (revision 53577) +++ libs/pool/test/test_pool_alloc.cpp (working copy) @@ -215,6 +215,13 @@ // clean up memory leak tmp->~tester(); boost::pool_allocator::deallocate(tmp, 1); + + // test allocating zero elements + { + boost::pool_allocator alloc; + tester* ip = alloc.allocate(0); + alloc.deallocate(ip, 0); + } } // This is a wrapper around a UserAllocator. It just registers alloc/dealloc