I have the following struct:
pub const MyStruct = struct {
allocator: Allocator,
count: u16,
code: []u8,
};
This is the function I use to create it:
pub fn initMyStruct(allocator: Allocator) !*MyStruct{
const code = try allocator.alloc(u8, 8);
var result = MyStruct{
.allocator = allocator,
.count = 0,
.code = code,
};
return &result;
}
Here's how I'm trying to destroy it (doesn't work):
pub fn freeMyStruct(my_struct: *MyStruct) void {
var allocator = my_struct.allocator;
freeArray(MyStruct, allocator, chunk.code);
}
pub fn freeArray(comptime T: type, allocator: Allocator, pointer: []T) void {
allocator.free(pointer);
}
I get a segfault when trying to free the slice. What am I doing wrong?