www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16252] New: Region allocator should not be copyable

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

          Issue ID: 16252
           Summary: Region allocator should not be copyable
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: lodovico giaretart.net

struct std.experimental.allocator.building_blocks.region.Region should have its
postblit disabled, at least when it has a non-empty destructor, i.e. when it
frees its store.

Consider the following code:

import std.experimental.allocator;
import std.experimental.allocator.mallocator;
import std.experimental.allocator.building_blocks.region;
import std.stdio: writeln;

void foo(Alloc)(Alloc alloc)
{
    writeln("alloc disposed...");
}

void main()
{
    auto alloc = Region!Mallocator(Mallocator.instance.allocate(128));
    auto ptr = alloc.make!int(3);
    writeln("*ptr = ", *ptr) // prints 3
    foo(alloc);
    writeln("*ptr = ", *ptr) // ops... invalid memory...
    // ops... alloc destructor trying to free again the block already freed by
foo
}

--
Jul 08 2016