False Positives on Methods/Functions That Return *http.Response
tsvanharen opened this issue · 3 comments
tsvanharen commented
For functions and methods that return a *http.Response and handle the closing of the response body by the function/method caller, this tool flags the response inside the function/method as needing to be closed, when it is being closed by the caller.
dcu commented
sample program:
package main
import (
"net/http"
)
func get() *http.Response {
resp, _ := http.Get("https://example.com")
return resp
}
func main() {
resp := get()
resp.Body.Close()
}
timakin commented
Fixed and added as a testcase.
https://github.com/timakin/bodyclose/blob/master/passes/bodyclose/testdata/src/a/issue1.go