https://issues.dlang.org/show_bug.cgi?id=16507

          Issue ID: 16507
           Summary: std.experimental.allocator: FreeTree clears too
                    eagerly
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nob...@puremagic.com
          Reporter: ag0ae...@gmail.com

Documentatinon [1] says: "If allocation from the parent succeeds, the allocated
block is returned. Otherwise, [...] FreeTree releases all of its contents and
tries again."

----
import std.experimental.allocator.building_blocks: FreeTree;

struct MyAllocator
{
    byte dummy;
    static bool alive = true;
    void[] allocate(size_t s) { return new byte[](s); }
    bool deallocate(void[] ) { if (alive) assert(false); return true; }
    enum alignment = size_t.sizeof;
}

void main()
{
    FreeTree!MyAllocator ft;
    void[] x = ft.allocate(1);
    ft.deallocate(x);
    ft.allocate(1000);
    MyAllocator.alive = false;
}
----

The assert is hit. It shouldn't be. For the second allocation, ft should
allocate from the parent allocator without deallocating the free block.

Pull request incoming.


[1]
http://dlang.org/phobos/std_experimental_allocator_building_blocks_free_tree.html#.FreeTree.allocate

--

Reply via email to