szn

Bug 116 — options.zig — choice values are not cloned or freed

116. options.zig — choice values are not cloned or freed

File: src/options.zig:158–163, 165–170 Severity: MEDIUM Status: ✅ FIXED — cloneValue now dupes choice strings; freeValue frees them. errdefers in init() and clone() now clean up already-cloned values on allocation failure. Tests added.

fn cloneValue(allocator: std.mem.Allocator, value: OptionValue) Error!OptionValue {
    return switch (value) {
        .string => |s| OptionValue{ .string = try allocator.dupe(u8, s) },
        inline else => value,
    };
}
fn freeValue(allocator: std.mem.Allocator, value: OptionValue) void {
    switch (value) {
        .string => |s| allocator.free(s),
        .number, .colour, .key, .flag, .choice => {},
    };
}

choice is []const u8 but is neither cloned on set nor freed on deinit. Currently safe only because all choice values in the codebase are string literals. If a dynamically-allocated choice string is ever passed to set, it will be a use-after-free (not cloned) or memory leak (not freed).