[Issue 18854] New: std.allocator: StatsCollector counts failed deallocations
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat May 12 01:23:28 UTC 2018
    
    
  
https://issues.dlang.org/show_bug.cgi?id=18854
          Issue ID: 18854
           Summary: std.allocator: StatsCollector counts failed
                    deallocations
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: dlang-bugzilla at thecybershadow.net
///////////////////////////// test.d /////////////////////////////
import std.exception : enforce;
import std.experimental.allocator.building_blocks.region;
import std.experimental.allocator.building_blocks.stats_collector;
import std.experimental.allocator.gc_allocator;
import std.typecons : Ternary;
void main()
{
    StatsCollector!(Region!GCAllocator, Options.bytesUsed) s;
    s.parent = Region!GCAllocator(1024);
    auto buf1 = s.allocate(100).enforce();
    auto buf2 = s.allocate(100).enforce();
    if (s.deallocate(buf1))
    {
        // OK
        return;
    }
    else
    {
        // Oops, have to deallocate buf2 first
        s.deallocate(buf2).enforce();
        s.deallocate(buf1).enforce();
        // The region should be empty now, right?
        assert(s.empty != Ternary.no); // Nope!
    }
}
//////////////////////////////////////////////////////////////////
--
    
    
More information about the Digitalmars-d-bugs
mailing list