From 56e72928c6e9ea554870d9673b71d280bfb50e09 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sat, 10 May 2025 12:46:34 -0400 Subject: fix use after free --- src/Client.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/Client.zig') diff --git a/src/Client.zig b/src/Client.zig index af78d39..57af48c 100644 --- a/src/Client.zig +++ b/src/Client.zig @@ -85,7 +85,7 @@ pub fn sendInitialConnection(payload: []const u8, initial_port: u16, allocator: base64Enc.calcSize(payload.len), ), ); - defer allocator.free(msg_bytes); + const msg: *SaprusMessage = .init(.connection, msg_bytes); const connection = (try msg.getSaprusTypePayload()).connection; @@ -120,8 +120,9 @@ pub fn connect(payload: []const u8, allocator: Allocator) !?SaprusConnection { try sock.bind(bind_addr); const msg = try sendInitialConnection(payload, initial_port, allocator); + defer allocator.free(msg.asBytes()); - var response_buf: [4096]u8 align(4) = @splat(0); + var response_buf: [4096]u8 align(@alignOf(SaprusMessage)) = undefined; _ = try sock.receive(&response_buf); // Ignore message that I sent. const len = try sock.receive(&response_buf); -- cgit