chore: remove all memory leaks

This commit is contained in:
2022-01-03 20:08:55 -06:00
parent 8257a3899a
commit 3aa680ab8c
6 changed files with 37 additions and 1 deletions

View File

@@ -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]));

View File

@@ -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]));
}