#GeneralPurposeAllocator crashing

1 messages · Page 1 of 1 (latest)

charred quail
#

Not sure if I'm being dumb, but doing zig run on the following file is causing some kind of memory error

const std = @import("std");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    _ = gpa.deinit();
    const allocator = gpa.allocator();

    const slice = try allocator.alloc(usize, 10);
    allocator.free(slice);
}
#

The error in question

General protection exception (no address available)
/home/aktriv/.zvm/master/lib/std/heap/general_purpose_allocator.zig:524:91: 0x107bedf in allocSlot (test)
            if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) {
                                                                                          ^
/home/aktriv/.zvm/master/lib/std/heap/general_purpose_allocator.zig:1015:44: 0x106c095 in allocInner (test)
            const slot = try self.allocSlot(new_size_class, ret_addr);
                                           ^
/home/aktriv/.zvm/master/lib/std/heap/general_purpose_allocator.zig:974:30: 0x103b314 in alloc (test)
            return allocInner(self, len, @as(Allocator.Log2Align, @intCast(log2_ptr_align)), ret_addr) catch return null;
                             ^
/home/aktriv/.zvm/master/lib/std/mem/Allocator.zig:86:29: 0x106dea4 in allocBytesWithAlignment__anon_7691 (test)
    return self.vtable.alloc(self.ptr, len, ptr_align, ret_addr);
                            ^
/home/aktriv/.zvm/master/lib/std/mem/Allocator.zig:211:40: 0x103ceed in allocWithSizeAndAlignment__anon_4150 (test)
    return self.allocBytesWithAlignment(alignment, byte_count, return_address);
                                       ^
/home/aktriv/.zvm/master/lib/std/mem/Allocator.zig:205:75: 0x10384b1 in alloc__anon_3501 (test)
    const ptr: [*]align(a) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address));
                                                                          ^
/home/aktriv/Projects/test.zig:8:38: 0x10382b1 in main (test)
    const slice = try allocator.alloc(usize, 10);
#
                                     ^
/home/aktriv/.zvm/master/lib/std/start.zig:570:37: 0x1038181 in posixCallMainAndExit (test)
            const result = root.main() catch |err| {
                                    ^
/home/aktriv/.zvm/master/lib/std/start.zig:240:5: 0x1037d6d in _start (test)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
stable gyro
charred quail
#

Oh the defer

stable gyro
#

lol yea sorry its late

charred quail
#

Yeah I was being dumb

#

thanks