Skip to content

Commit

Permalink
fix: fix issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeShpak committed Apr 19, 2023
1 parent e39cf3f commit c5c4a16
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions passes/bodyclose/bodyclose.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ func (r *runner) getResVal(instr ssa.Instruction) (ssa.Value, bool) {
if instr.Type().String() == r.resTyp.String() {
return instr, true
}
case *ssa.Store:
if instr.Val.Type().String() == r.resTyp.String() {
return instr.Val, true
}
}
return nil, false
}
Expand Down
26 changes: 26 additions & 0 deletions passes/bodyclose/testdata/src/a/issue11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package a

import (
"io"
"net/http"
"net/http/httptest"
)

func getResponse(url string) *http.Response {
res, _ := http.Get(url)
return res
}

func issue11_1() {
resp := getResponse("https://example.com")
resp.Body.Close()
}

func issues11_2() {
w := httptest.NewRecorder()
resp := w.Result()
defer func() {
_ = resp.Body.Close()
}()
_, _ = io.ReadAll(resp.Body)
}

0 comments on commit c5c4a16

Please sign in to comment.