github-vet / github-vet/rangeloop-pointer-findings
sejvlond/tarsier: handlers.go; 31 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [sejvlond/tarsier](https://www.github.com/sejvlond/tarsier) at [handlers.go](https://github.com/sejvlond/tarsier/blob/4b9d59c1ea3c101cb9f812c800ddff0712e90e12/handlers.go#L111-L141)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable buddy used in defer or goroutine at line 118
[Click here to see the code in its original context.](https://github.com/sejvlond/tarsier/blob/4b9d59c1ea3c101cb9f812c800ddff0712e90e12/handlers.go#L111-L141)
Click here to show the 31 line(s) of Go which triggered the analyzer.
```go
for _, buddy := range buddies {
// send wave in goroutine and do not wait for it
wg.Add(1)
go func() {
defer wg.Done()
buf := bytes.NewReader(b)
resp, err := h.client.Post(
fmt.Sprintf("%v:%v/exec", buddy.Address, buddy.Port),
"application/x-yaml", buf)
if err != nil {
h.lgr.Errorf("Could not send wave to buddy %v:%v '%v'",
buddy.Address, buddy.Port, err)
return
}
data, _ := ioutil.ReadAll(resp.Body)
err = resp.Body.Close()
if err != nil {
h.lgr.Errorf("Error while closing response body: '%v'", err)
}
h.lgr.Infof("Response from buddy %v:%v is '%s'",
buddy.Address, buddy.Port, string(data))
_, err = w.Write([]byte(fmt.Sprintf(
"Buddy %v:%v says: %v", buddy.Address, buddy.Port,
string(data))))
if err != nil {
h.lgr.Errorf("Writing command output from buddy %v:%v"+
"failed '%v'", buddy.Address, buddy.Port, err)
}
}()
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 4b9d59c1ea3c101cb9f812c800ddff0712e90e12
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.