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
This commit is contained in:
raul 2024-04-14 09:27:17 +02:00
parent ca10bc4284
commit c85fa5b031
1 changed files with 5 additions and 1 deletions

View File

@ -35,7 +35,11 @@ func listener(g *gocui.Gui, conn net.Conn) {
} }
for { for {
reply := make([]byte, 2048) 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)) fmt.Fprintln(chatbox, string(reply))
termbox.Interrupt() termbox.Interrupt()