2024: Day 2/3 ensure deferred input deinit

This commit is contained in:
Andrew Scott 2024-12-11 03:02:51 -05:00
parent 4f7f33cc75
commit f75fb88668
Signed by: a
GPG key ID: 7CD5A5977E4931C1
2 changed files with 13 additions and 0 deletions

View file

@ -18,6 +18,7 @@ pub fn main() !void {
const allocator = gpa.allocator(); const allocator = gpa.allocator();
const input = try util.readAllInput(2, allocator); const input = try util.readAllInput(2, allocator);
defer allocator.free(input);
var safe: u16 = 0; var safe: u16 = 0;
var safe_with_dampener: u16 = 0; var safe_with_dampener: u16 = 0;

View file

@ -96,6 +96,7 @@ pub fn maybeScan(comptime T: type, window: *std.mem.WindowIterator(T)) !u32 {
pub fn main() !void { pub fn main() !void {
const input = try util.readAllInput(3, allocator); const input = try util.readAllInput(3, allocator);
defer allocator.free(input);
var mul = MulOp.init(); var mul = MulOp.init();
var window = std.mem.window(u8, input, 12, 1); var window = std.mem.window(u8, input, 12, 1);
@ -107,3 +108,14 @@ pub fn main() !void {
log.info("PART 1: {d}\n", .{p1}); log.info("PART 1: {d}\n", .{p1});
log.info("PART 2: {d}\n", .{p2}); log.info("PART 2: {d}\n", .{p2});
} }
test "memory" {
const input = try util.readAllInput(3, std.testing.allocator);
defer std.testing.allocator.free(input);
var mul = MulOp.init();
var window = std.mem.window(u8, input, 12, 1);
const res = try scanForUncorrupted(u8, &window, &mul, 1);
try std.testing.expect(res > 0);
}