[Issue 18347] stdx.allocator dispose should be @safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 1 15:38:52 UTC 2018


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

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g at gmail.com

--- Comment #1 from ag0aep6g at gmail.com ---
How do you suppose `dispose` can be safe here? Mallocator doesn't do reference
counting, so `dispose` doesn't detect any existing references except the one
you pass.

In code:

----
alias alloc = Mallocator.instance;
auto p1 = alloc.makeArray!ubyte(20);
auto p2 = p1; /* Another reference to the same data. */
alloc.dispose(p); /* Nulling p1 but not p2. */
ubyte x = p2[0]; /* Dereferencing a dangling pointer. */
----

--


More information about the Digitalmars-d-bugs mailing list