D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16506 - segfaults in std.experimental.allocator: FreeTree with GCAllocator or Mallocator
Summary: segfaults in std.experimental.allocator: FreeTree with GCAllocator or Mallocator
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: ag0aep6g
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2016-09-17 22:46 UTC by ag0aep6g
Modified: 2016-10-01 11:47 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2016-09-17 22:46:47 UTC
Found by Ryan who posted to the Learn group:
http://forum.dlang.org/post/vuhulvwgtahinnknntvv@forum.dlang.org

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 Lodovico Giaretta 2016-09-18 10:45:32 UTC
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 ag0aep6g 2016-09-18 22:19:55 UTC
https://github.com/dlang/phobos/pull/4798
Comment 3 github-bugzilla 2016-09-24 19:45:45 UTC
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 github-bugzilla 2016-10-01 11:47:15 UTC
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