melody
melody copied to clipboard
Check returned errors before deferring Close()
This pattern is repeated several times in melody_test.go:
conn, err := NewDialer(server.URL)
defer conn.Close()
if err != nil {
t.Error(err)
return false
}
However, if there is an error, this is liable to cause a null reference panic.
@riking the defer
clause should be placed after the if
block, the correct code may looks like below:
conn, err := NewDialer(server.URL)
if err != nil {
t.Error(err)
return false
}
defer conn.Close()
A good luck to you if it can solve the problem.