From 4bc6aac4e9ca17bb80932a48482f242241db3a24 Mon Sep 17 00:00:00 2001 From: namedkitten Date: Tue, 28 Jul 2020 10:02:16 +0100 Subject: [PATCH] Fix allocator scope. --- src/main.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4a49019..fc57758 100644 --- a/src/main.zig +++ b/src/main.zig @@ -50,16 +50,21 @@ pub fn log( pub fn main() !void { std.log.info(.main, "Starting Bar.", .{}); var allocator: *std.mem.Allocator = undefined; - var dbgAlloc: *DebugAllocator = undefined; + var dbgAlloc: DebugAllocator = undefined; + var arena: std.heap.ArenaAllocator = undefined; if (debug_allocator) { // Warning that DebugAllocator can get a little crashy. - dbgAlloc = &DebugAllocator.init(std.heap.page_allocator, 8192 * 8192); + dbgAlloc = DebugAllocator.init(std.heap.page_allocator, 8192 * 8192); allocator = &dbgAlloc.allocator; } else { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); - defer arena.deinit(); + arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); allocator = &arena.allocator; } + defer { + if (!debug_allocator) arena.deinit(); + } + + var bar = barImpl.initBar(allocator); var br = Bar.init(&bar);