Skip to content
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

Allocating with arena and also its child allocator (HeapAllocator at least) causes crash #5830

Closed
lxn opened this issue Jul 9, 2020 · 0 comments · Fixed by #6383
Closed

Comments

@lxn
Copy link

lxn commented Jul 9, 2020

This is on Windows 10 using zig-windows-x86_64-0.6.0+12a7dedb1.zip.

No problems before recent Allocator changes.

const std = @import("std");

pub fn main() anyerror!void {
    var heap_allocator = std.heap.HeapAllocator.init();
    defer heap_allocator.deinit();
    const allocator = &heap_allocator.allocator;

    var arena = std.heap.ArenaAllocator.init(allocator);
    defer arena.deinit();
    const arena_allocator = &arena.allocator;

    // Allocating an u8 instead of u16 for foo would avoid the crash on allocating bar.
    const foo = try arena_allocator.create(u16);

    // Allocating bar before foo would crash on "defer arena.deinit();" instead.
    const bar = try allocator.create(u8);
    defer allocator.destroy(bar);
}
LemonBoy added a commit to LemonBoy/zig that referenced this issue Sep 19, 2020
HeapAllocator stores the pointer returned by HeapAlloc right after the
data block and, after the recent allocator refactoring, the space for
this pointer was not taken into account in the calculation of the final
block size.

Fixes ziglang#5830
andrewrk pushed a commit that referenced this issue Sep 20, 2020
HeapAllocator stores the pointer returned by HeapAlloc right after the
data block and, after the recent allocator refactoring, the space for
this pointer was not taken into account in the calculation of the final
block size.

Fixes #5830
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant