fix use after free

This commit is contained in:
2025-05-10 12:46:34 -04:00
parent a80c9abfe7
commit 56e72928c6

View File

@@ -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);