Ticket #386: pool.patch

File pool.patch, 1.7 KB (added by Steven Watanabe, 13 years ago)

patch and test case.

  • boost/pool/simple_segregated_storage.hpp

     
    147147    void free_n(void * const chunks, const size_type n,
    148148        const size_type partition_size)
    149149    {
    150       add_block(chunks, n * partition_size, partition_size);
     150      if(n != 0)
     151        add_block(chunks, n * partition_size, partition_size);
    151152    }
    152153
    153154    // pre: chunks was previously allocated from *this with the same
     
    156157    void ordered_free_n(void * const chunks, const size_type n,
    157158        const size_type partition_size)
    158159    {
    159       add_ordered_block(chunks, n * partition_size, partition_size);
     160      if(n != 0)
     161        add_ordered_block(chunks, n * partition_size, partition_size);
    160162    }
    161163};
    162164
     
    247249void * simple_segregated_storage<SizeType>::malloc_n(const size_type n,
    248250    const size_type partition_size)
    249251{
     252  if(n == 0)
     253    return 0;
    250254  void * start = &first;
    251255  void * iter;
    252256  do
  • libs/pool/test/test_pool_alloc.cpp

     
    215215  //  clean up memory leak
    216216  tmp->~tester();
    217217  boost::pool_allocator<tester>::deallocate(tmp, 1);
     218
     219  // test allocating zero elements
     220  {
     221      boost::pool_allocator<tester> alloc;
     222      tester* ip = alloc.allocate(0);
     223      alloc.deallocate(ip, 0);
     224  }
    218225}
    219226
    220227// This is a wrapper around a UserAllocator.  It just registers alloc/dealloc