chore: remove all memory leaks
This commit is contained in:
@@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
pub const Bios = struct {
|
||||
buf: []u8,
|
||||
alloc: Allocator,
|
||||
|
||||
pub fn init(alloc: Allocator, path: []const u8) !@This() {
|
||||
const file = try std.fs.cwd().openFile(path, .{ .read = true });
|
||||
@@ -13,9 +14,14 @@ pub const Bios = struct {
|
||||
|
||||
return @This(){
|
||||
.buf = try file.readToEndAlloc(alloc, len),
|
||||
.alloc = alloc,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.alloc.free(self.buf);
|
||||
}
|
||||
|
||||
pub inline fn get32(self: *const @This(), idx: usize) u32 {
|
||||
std.debug.panic("[BIOS] TODO: BIOS is not implemented", .{});
|
||||
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
|
||||
|
@@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
pub const GamePak = struct {
|
||||
buf: []u8,
|
||||
alloc: Allocator,
|
||||
|
||||
pub fn init(alloc: Allocator, path: []const u8) !@This() {
|
||||
const file = try std.fs.cwd().openFile(path, .{ .read = true });
|
||||
@@ -13,9 +14,14 @@ pub const GamePak = struct {
|
||||
|
||||
return @This(){
|
||||
.buf = try file.readToEndAlloc(alloc, len),
|
||||
.alloc = alloc,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.alloc.free(self.buf);
|
||||
}
|
||||
|
||||
pub inline fn get32(self: *const @This(), idx: usize) u32 {
|
||||
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
|
||||
}
|
||||
|
Reference in New Issue
Block a user