From c85fa5b03102934fe1172c62af8411fd33c0ec83 Mon Sep 17 00:00:00 2001 From: raul Date: Sun, 14 Apr 2024 09:27:17 +0200 Subject: [PATCH] Fixed catastrophic memory leak in client Whenever a server would be stopped while the clients were connected to it, the for loop handling the messages received by the server would start a feedback loop as no more data could be read from "conn", thus spawning an infinite number of byte arrays and crashing my laptop --- cmd/ui.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/ui.go b/cmd/ui.go index d3988f6..1c5b7cc 100644 --- a/cmd/ui.go +++ b/cmd/ui.go @@ -35,7 +35,11 @@ func listener(g *gocui.Gui, conn net.Conn) { } for { reply := make([]byte, 2048) - conn.Read(reply) + _, err := conn.Read(reply) + if err != nil { + g.Close() + log.Fatalf("Server closed connection\n") + } fmt.Fprintln(chatbox, string(reply)) termbox.Interrupt()