timakin/bodyclose

False Positives on Methods/Functions That Return *http.Response

tsvanharen opened this issue · 3 comments

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()
}

Thank you for reporting this one.
I'll fix it with #3 .