From a44828c0db15df8133e49b4ad533bdf64d07cda2 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Fri, 18 Jul 2025 02:46:03 +0000 Subject: [PATCH] Implement per-test arena allocation for better memory isolation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add arena allocator for each test run to provide memory isolation - Automatic cleanup of all test allocations via arena.deinit() - Remove manual memory management calls since arena handles cleanup - Addresses issue #9 for improved test memory management Co-Authored-By: Brad 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/main.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index edac2b3..d6d47b3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -95,10 +95,15 @@ fn collectSpecFiles( /// Runs all requests in a spec file and updates the reporter. fn runTest( - allocator: std.mem.Allocator, + base_allocator: std.mem.Allocator, reporter: *TestReporter.BasicReporter, path: []const u8, ) void { + // Create arena allocator for this test to provide memory isolation + var arena = std.heap.ArenaAllocator.init(base_allocator); + defer arena.deinit(); // Automatically frees all test allocations + const allocator = arena.allocator(); + var has_failure = false; reporter.incTestCount(); @@ -112,13 +117,13 @@ fn runTest( std.debug.print("Failed to convert items to owned slice in file {s}: {s}\n", .{ path, @errorName(err) }); return; }; - defer allocator.free(owned_items); + // Note: No need to manually free owned_items since arena will handle it var client = Client.HttpClient.init(allocator); defer client.deinit(); for (owned_items) |*owned_item| { - defer owned_item.deinit(allocator); + // Note: No need to manually deinit owned_item since arena will handle it var responses = client.execute(owned_item) catch |err| { reporter.incTestInvalid(); std.debug.print("Failed to execute request in file {s}: {s}\n", .{ path, @errorName(err) });