-
Notifications
You must be signed in to change notification settings - Fork 61
dparse: Fix memory corruption #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| module dparse.stack_buffer; | ||
|
|
||
| import core.memory : GC; | ||
|
|
||
| import std.traits; | ||
|
|
||
| //version = debug_stack_allocator; | ||
|
|
@@ -20,14 +22,21 @@ struct StackBuffer | |
| static if (is(T == class)) | ||
| static assert(T.sizeof == size_t.sizeof); | ||
|
|
||
| static if (hasIndirections!T) | ||
| while (_length % size_t.sizeof != 0) | ||
| put(ubyte(1)); | ||
|
|
||
| if (arr.ptr != stackSpace.ptr) | ||
| { | ||
| if (_length + T.sizeof > arr.length) | ||
| { | ||
| size_t newLength = arr.length << 1; | ||
| while (_length + T.sizeof > newLength) | ||
| newLength <<= 1; | ||
| auto oldPtr = arr.ptr; | ||
| Mallocator.instance.reallocate(arr, newLength); | ||
| GC.removeRange(oldPtr); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a race condition here, which is unavoidable with the We need to call A bit surprising that Also note that we can't make this call conditional on |
||
| GC.addRange(arr.ptr, arr.length); | ||
| version (debug_stack_allocator) | ||
| (cast(ubyte[]) arr)[_length .. $] = 0; | ||
| } | ||
|
|
@@ -38,6 +47,7 @@ struct StackBuffer | |
| while (_length + T.sizeof > newLength) | ||
| newLength <<= 1; | ||
| arr = Mallocator.instance.allocate(newLength); | ||
| GC.addRange(arr.ptr, arr.length); | ||
| version (debug_stack_allocator) | ||
| (cast(ubyte[]) arr)[] = 0; | ||
| arr[0 .. stackSpace.length] = stackSpace[]; | ||
|
|
@@ -54,7 +64,10 @@ struct StackBuffer | |
| version (debug_stack_allocator) | ||
| (cast(ubyte[]) arr)[] = 0; | ||
| if (arr.ptr !is stackSpace.ptr) | ||
| { | ||
| GC.removeRange(arr.ptr); | ||
| Mallocator.instance.deallocate(arr); | ||
| } | ||
| } | ||
|
|
||
| void[] opSlice() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.