Bug 16506 – segfaults in std.experimental.allocator: FreeTree with GCAllocator or Mallocator

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-09-17T22:46:00Z
Last change time
2016-10-01T11:47:15Z
Keywords
pull
Assigned to
ag0aep6g
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2016-09-17T22:46:47Z
Found by Ryan who posted to the Learn group: http://forum.dlang.org/post/[email protected] Reduced test case: ---- import std.experimental.allocator: dispose, makeArray; import std.experimental.allocator.gc_allocator: GCAllocator; import std.experimental.allocator.mallocator: Mallocator; import std.experimental.allocator.building_blocks: FreeTree; void f(ParentAllocator)(size_t sz) { static FreeTree!ParentAllocator myAlloc; byte[] _payload = myAlloc.makeArray!byte(sz, 0); assert(_payload, "_payload is null"); /* passes */ myAlloc.dispose(_payload); } version(malloc) void main() { f!Mallocator(33); f!Mallocator(43); } version (gc) void main() { f!GCAllocator(1); } ---- Both versions segfault in Linux. The malloc version seems to need slightly different numbers for the second call, depending on details like the version of dmd. On my machine, compiled with git master dmd, the segfaults occurs with a value of 41 or higher, and 2.071.1 needs 42 or higher. On DPaste, 2.071.1 needs 43 or higher. No segfault with Windows dmd, tested in Wine.
Comment #1 by lodovico — 2016-09-18T10:45:32Z
With the malloc version, I got this output: malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed. To me, it looks like the problem is specific to FreeTree. Changing the title to reflect this.
Comment #2 by ag0aep6g — 2016-09-18T22:19:55Z
Comment #3 by github-bugzilla — 2016-09-24T19:45:45Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/2a2e04b9c7b0c7fa10b22254b95aa2cb7826a82c fix issue 16506 - segfaults in std.experimental.allocator: FreeTree with GCAllocator or Mallocator https://github.com/dlang/phobos/commit/25418edb0611ca6de06c6a8d7281407cd4c9a2e6 Merge pull request #4798 from aG0aep6G/FreeTree std.experimental.allocator: fix FreeTree issues 16506 and 16507
Comment #4 by github-bugzilla — 2016-10-01T11:47:15Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/2a2e04b9c7b0c7fa10b22254b95aa2cb7826a82c fix issue 16506 - segfaults in std.experimental.allocator: FreeTree with GCAllocator or Mallocator https://github.com/dlang/phobos/commit/25418edb0611ca6de06c6a8d7281407cd4c9a2e6 Merge pull request #4798 from aG0aep6G/FreeTree