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:
parent
ca10bc4284
commit
c85fa5b031
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue