I've got code that looks like this:
if (parsed_args.args.mapfile) |mapfile| {
input.map_file = mapfile;
} else {
// option B: find the map in tfpath based on the name in the demo header
input.map_file = try get_map_absolute_path(allocator, &input, &parsed_args, ¶ms);
}
defer allocator.free(input.map_file.?);
If I dont have mapfile in args, then input.map_file is a heap-allocated pointer, and everything works fine. If I supply mapfile to the program, it panics with invalid free. If I put the defer in the conditional then it will get removed right away. Whats the Zig Way to do this?