On 31/12/2016 3:32 PM, David Zhang wrote:
On Saturday, 31 December 2016 at 02:03:07 UTC, rikki cattermole wrote:
As it should, current is never reassigned.
You only need one var, next. Of course I didn't read the entire thread
chain so, I'm probably missing something.

import std.experimental.allocator;

void main() {
        struct S { S* next; }
        S* _foo;
        foreach (e; 0 .. 10)
                _foo = theAllocator.make!S(_foo);
        S* next;

        next = _foo;
        while(next !is null) {
                auto nextT = next.next;
                theAllocator.dispose(next);
                next = nextT;
        }
}

Thanks for your response. So next is never null, and thus there is an
infinite loop, correct? If so, why does dub indicate that all tests are
complete?

No, my understand is thus:

 next = current.next;
 theAllocator.dispose(current);

When current is deallocated, current is pointing to free'd memory.
After that point it should be segfaulting when you try to access it *I think*.

Reply via email to