zig/test/cases/decl_value_arena.zig
kcbanner 2b592d7e3c sema: Rework Decl.value_arena to fix another memory corruption issue
This fixes a bug where resolveStructLayout to was promoting from stale
value_arena state which was then overwrriten when another ArenaAllocator
higher in the call stack saved its state back. This resulted in the memory
for struct_obj.optmized_order overlapping existing allocations.

My initial fix in c7067ef wasn't sufficient, as it only checked if the struct being
resolved had the same owner as the current sema instance. However, it's
possible for resolveStructLayout to be called when the sema instance
has a different owner, but the struct decl's value_arena is currently in
use higher up in the callstack.

This change introduces ValueArena, which holds the arena state as well as tracks
if an arena has already been promoted from it. This allows callers to use the
value_arena storage without needing to be aware of another user of this same storage
higher up in the call stack.
2023-04-27 01:11:57 -04:00

22 lines
394 B
Zig

pub const Protocols: struct {
list: *const fn(*Connection) void = undefined,
handShake: type = struct {
const stepStart: u8 = 0;
},
} = .{};
pub const Connection = struct {
streamBuffer: [0]u8 = undefined,
__lastReceivedPackets: [0]u8 = undefined,
handShakeState: u8 = Protocols.handShake.stepStart,
};
pub fn main() void {
var conn: Connection = undefined;
_ = conn;
}
// run
//