oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git

Added arena allocator for caonfig file to manage lua string lifetimes.

Commit
c9d3f927825480bccfef00ff86770c297d9b6620
Parent
9d04f08
Author
tonybanters <tonybanters@gmail.com>
Date
2026-02-17 22:53:14

Diff

diff --git a/src/config/config.zig b/src/config/config.zig
index 7c7f918..031eda0 100644
--- a/src/config/config.zig
+++ b/src/config/config.zig
@@ -109,6 +109,7 @@ pub const Color_Scheme = struct {
 
 pub const Config = struct {
     allocator: std.mem.Allocator,
+    string_arena: std.heap.ArenaAllocator,
 
     terminal: []const u8 = "st",
     font: []const u8 = "monospace:size=10",
@@ -149,10 +150,12 @@ pub const Config = struct {
     pub fn init(allocator: std.mem.Allocator) Config {
         return Config{
             .allocator = allocator,
+            .string_arena = std.heap.ArenaAllocator.init(allocator),
         };
     }
 
     pub fn deinit(self: *Config) void {
+        self.string_arena.deinit();
         self.keybinds.deinit(self.allocator);
         self.rules.deinit(self.allocator);
         self.blocks.deinit(self.allocator);
diff --git a/src/config/lua.zig b/src/config/lua.zig
index 2ff93ca..272b60a 100644
--- a/src/config/lua.zig
+++ b/src/config/lua.zig
@@ -1161,7 +1161,8 @@ fn get_lua_string(state: *c.lua_State, idx: c_int) ?[]const u8 {
 fn dupe_lua_string(state: *c.lua_State, idx: c_int) ?[]const u8 {
     const cfg = config orelse return null;
     const lua_str = get_lua_string(state, idx) orelse return null;
-    const duped = cfg.allocator.dupe(u8, lua_str) catch return null;
+    const arena_allocator = cfg.string_arena.allocator();
+    const duped = arena_allocator.dupe(u8, lua_str) catch return null;
     return duped;
 }
 
diff --git a/src/main.zig b/src/main.zig
index 5c1225d..cda2138 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -136,8 +136,10 @@ pub fn main() !void {
     const allocator = gpa.allocator();
     defer _ = gpa.deinit();
 
-    var config_path: []const u8 = try get_config_path(allocator);
-    defer allocator.free(config_path);
+    const default_config_path = try get_config_path(allocator);
+    defer allocator.free(default_config_path);
+
+    var config_path: []const u8 = default_config_path;
     var args = std.process.args();
     _ = args.skip();
     while (args.next()) |arg| {
@@ -218,6 +220,19 @@ pub fn main() !void {
     std.debug.print("entering event loop\n", .{});
     run_event_loop(&display);
 
+    bar_mod.destroy_bars(allocator, display.handle);
+
+    var mon = monitor_mod.monitors;
+    while (mon) |m| {
+        const next = m.next;
+        monitor_mod.destroy(m);
+        mon = next;
+    }
+
+    if (keybind_overlay) |overlay| {
+        overlay.deinit(allocator);
+    }
+
     lua.deinit();
     std.debug.print("oxwm exiting\n", .{});
 }