github-vet / github-vet/rangeloop-pointer-findings

riking/marvin: intra/cdnproxy/proxy.go; 34 LoC

Open
#7,030 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [riking/marvin](https://www.github.com/riking/marvin) at [intra/cdnproxy/proxy.go](https://github.com/riking/marvin/blob/d726a1aa538a81e65c04959c2f2177549638b962/intra/cdnproxy/proxy.go#L138-L171)

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 resp used in defer or goroutine at line 160

[Click here to see the code in its original context.](https://github.com/riking/marvin/blob/d726a1aa538a81e65c04959c2f2177549638b962/intra/cdnproxy/proxy.go#L138-L171)

Click here to show the 34 line(s) of Go which triggered the analyzer.

```go
for resp := range respCh {
if resp == nil {
continue
}
if gotResponse {
// don't need you
resp.Body.Close()
continue
}

if resp.StatusCode == 200 || resp.StatusCode == 206 {
// GOT IT
gotResponse = true
for k, v := range resp.Header {
if k == "Server" || k == "Connection" || k == "Access-Control-Allow-Origin:" {
continue
}
w.Header()[k] = v
}
w.WriteHeader(resp.StatusCode)
bodyDoneWg.Add(1)
go func() {
io.Copy(w, resp.Body)
resp.Body.Close()
bodyDoneWg.Done()
}()
continue
} else if resp.StatusCode == 404 {
any404 = true
} else {
errCh <- fmt.Errorf("proxy: backing server returned unexpected status code %d", resp.StatusCode)
}
resp.Body.Close()
}

```

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: d726a1aa538a81e65c04959c2f2177549638b962

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.