February 15, 2006 Custom allocator + empty class = crash | ||||
---|---|---|---|---|
| ||||
The following is a modified version of the custom allocator example in the docs. The class has to be empty, ie. without any members, for the crash to occur. Still I thought I should report it since it might be a symptom of a deeper problem. # import std.c.stdlib; # import std.outofmemory; # import std.gc; # import std.stdio; # # class Foo # { # new(uint sz) # { # void* p; # # p = std.c.stdlib.malloc(sz); # # if (!p) throw new OutOfMemoryException(); # # addRange(p, p + sz); # # writefln("Allocated %d bytes at ", sz, p); # # return p; # } # # delete(void* p) # { # writefln("Freeing ", p); // This line is never reached # if (p) # { # removeRange(p); # std.c.stdlib.free(p); # } # writefln(p, " is free!"); # } # } # # void main() # { # Foo f = new Foo; # delete f; // The delete command causes the crash # } Output: Allocated 8 bytes at 93072f8 Segmentation fault Nick |
February 16, 2006 Re: Custom allocator + empty class = crash | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Attachments: | Nick schrieb am 2006-02-15: > The following is a modified version of the custom allocator example in the docs. The class has to be empty, ie. without any members, for the crash to occur. Still I thought I should report it since it might be a symptom of a deeper problem. > > # import std.c.stdlib; > # import std.outofmemory; > # import std.gc; > # import std.stdio; > # > # class Foo > # { > # new(uint sz) > # { > # void* p; > # > # p = std.c.stdlib.malloc(sz); > # > # if (!p) throw new OutOfMemoryException(); > # > # addRange(p, p + sz); > # > # writefln("Allocated %d bytes at ", sz, p); > # > # return p; > # } > # > # delete(void* p) > # { > # writefln("Freeing ", p); // This line is never reached > # if (p) > # { > # removeRange(p); > # std.c.stdlib.free(p); > # } > # writefln(p, " is free!"); > # } > # } > # > # void main() > # { > # Foo f = new Foo; > # delete f; // The delete command causes the crash > # } > > Output: > Allocated 8 bytes at 93072f8 > Segmentation fault > > Nick Added to DStress as http://dstress.kuehne.cn/run/d/delete_12_A.d http://dstress.kuehne.cn/run/d/delete_12_B.d http://dstress.kuehne.cn/run/d/delete_12_C.d http://dstress.kuehne.cn/run/d/delete_12_D.d Thomas |
Copyright © 1999-2021 by the D Language Foundation