Fix double free

was freeing the wrong element before.
This commit is contained in:
2026-01-03 02:32:27 +00:00
parent 5a7d3caf9c
commit f99b44fdb2

View File

@@ -133,7 +133,9 @@ fn handleConnectionInfallible(
id: usize, id: usize,
stream: std.Io.net.Stream, stream: std.Io.net.Stream,
) void { ) void {
handleConnection(server, server_allocator, io, id, stream) catch {}; handleConnection(server, server_allocator, io, id, stream) catch |err| {
std.log.err("Failed processing client {d}: {any}", .{ id, err });
};
} }
fn handleConnection( fn handleConnection(
@@ -322,8 +324,9 @@ fn unsubscribe(server: *Server, io: std.Io, gpa: std.mem.Allocator, id: usize, m
try server.subs_lock.lock(io); try server.subs_lock.lock(io);
defer server.subs_lock.unlock(io); defer server.subs_lock.unlock(io);
const len = server.subscriptions.items.len; const len = server.subscriptions.items.len;
for (0..len) |i| { for (0..len) |from_end| {
const sub = server.subscriptions.items[len - i - 1]; const i = len - from_end - 1;
const sub = server.subscriptions.items[i];
if (sub.client_id == id and std.mem.eql(u8, sub.sid, msg.sid)) { if (sub.client_id == id and std.mem.eql(u8, sub.sid, msg.sid)) {
gpa.free(sub.sid); gpa.free(sub.sid);
gpa.free(sub.subject); gpa.free(sub.subject);