A question on memory

fn bar(allocator:std.mem.allocator) []Foo {
    var foo: []Foo = try allocator.alloc(Foo, 3);

    return foo[..2];
}

with the above function, the function that calls bar frees the returned slice.
question is, is this legal behavior, freeing a slice of a slice? would it properly free the original slice?

No. One must free the exact slice that was allocated.

1 Like