-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: initialize an external context is regarded as context leak? #31856
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
Comments
Seems like a bug in the analyzer. If the cancel variable has package scope (x.Parent() == x.Pkg().Scope()) it should suppress the finding. |
@alandonovan This case also complained by go vet, but looks more reasonable: // Test for Go issue 31856.
func _() {
var cancel func()
func() {
_, cancel = context.WithCancel(bg)
}()
cancel()
} I have filed a PR, should fix this issue. |
Change https://golang.org/cl/175617 mentions this issue: |
…ent function scope See golang/go#31856. Change-Id: I229a7f4a48e7806df62941f801302b6da8a0c12b GitHub-Last-Rev: 33f8523 GitHub-Pull-Request: #95 Reviewed-on: https://go-review.googlesource.com/c/tools/+/175617 Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
@andybons The related PR is merged, this issue shouldn't be labled as |
In future, you can write "Fixes golang/go#xxxx" if you want CLs to automatically close issues when they are merged. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Variables context, cancel are declared at toplevel, function
Foo
is used to to initialize them,Indeed this code is quite poor, but is it really fine to be regard as an error?
https://play.golang.org/p/fHQ_fEu0GLW
What did you expect to see?
go vet
reports nothing.What did you see instead?
go vet
reports lostcancel error:The text was updated successfully, but these errors were encountered: