Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check returned errors before deferring Close() #60

Open
riking opened this issue Oct 16, 2019 · 1 comment
Open

Check returned errors before deferring Close() #60

riking opened this issue Oct 16, 2019 · 1 comment
Labels

Comments

@riking
Copy link

riking commented Oct 16, 2019

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.

@olahol olahol added the bug label Sep 14, 2022
@CodeDing
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants