github-vet / github-vet/rangeloop-pointer-findings
zachlatta/suck: suck.go; 51 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [zachlatta/suck](https://www.github.com/zachlatta/suck) at [suck.go](https://github.com/zachlatta/suck/blob/3e1c600c9e387e9ca8dcd346e14041575aa90297/suck.go#L112-L162)
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 req used in defer or goroutine at line 146
[Click here to see the code in its original context.](https://github.com/zachlatta/suck/blob/3e1c600c9e387e9ca8dcd346e14041575aa90297/suck.go#L112-L162)
Click here to show the 51 line(s) of Go which triggered the analyzer.
```go
for req := range ch {
requestsMade++
start := time.Now()
resp, err := client.Do(req.Request)
if err != nil {
fmt.Println(err)
}
code := 0
size := int64(-1)
if resp != nil {
if resp.ContentLength > 0 {
size = resp.ContentLength
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
reader := bytes.NewReader(body)
go func(body io.Reader, base *url.URL) {
links := links(body)
for _, link := range links {
link = base.ResolveReference(link)
if !urls.Exists(link.String()) {
urlsFound++
urls.Add(link.String())
nextReq, err := http.NewRequest("GET", link.String(), nil)
if err != nil {
fmt.Println(err)
}
s.jobs <- &request{nextReq, req.URL}
}
}
}(reader, req.URL)
resp.Body.Close()
}
s.results <- &result{
url: req.URL,
referer: req.referer,
statusCode: code,
duration: time.Now().Sub(start),
err: err,
contentLength: size,
}
}
```
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: 3e1c600c9e387e9ca8dcd346e14041575aa90297
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.