Skip to content

Commit a44828c

Browse files
claude[bot]claude
andcommitted
Implement per-test arena allocation for better memory isolation
- 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 <bradcypert@users.noreply.github.com> 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4f695b4 commit a44828c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ fn collectSpecFiles(
9595

9696
/// Runs all requests in a spec file and updates the reporter.
9797
fn runTest(
98-
allocator: std.mem.Allocator,
98+
base_allocator: std.mem.Allocator,
9999
reporter: *TestReporter.BasicReporter,
100100
path: []const u8,
101101
) void {
102+
// Create arena allocator for this test to provide memory isolation
103+
var arena = std.heap.ArenaAllocator.init(base_allocator);
104+
defer arena.deinit(); // Automatically frees all test allocations
105+
const allocator = arena.allocator();
106+
102107
var has_failure = false;
103108
reporter.incTestCount();
104109

@@ -112,13 +117,13 @@ fn runTest(
112117
std.debug.print("Failed to convert items to owned slice in file {s}: {s}\n", .{ path, @errorName(err) });
113118
return;
114119
};
115-
defer allocator.free(owned_items);
120+
// Note: No need to manually free owned_items since arena will handle it
116121

117122
var client = Client.HttpClient.init(allocator);
118123
defer client.deinit();
119124

120125
for (owned_items) |*owned_item| {
121-
defer owned_item.deinit(allocator);
126+
// Note: No need to manually deinit owned_item since arena will handle it
122127
var responses = client.execute(owned_item) catch |err| {
123128
reporter.incTestInvalid();
124129
std.debug.print("Failed to execute request in file {s}: {s}\n", .{ path, @errorName(err) });

0 commit comments

Comments
 (0)