github-vet / github-vet/rangeloop-pointer-findings
rancher/rio: cli/cmd/images/image.go; 70 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [rancher/rio](https://www.github.com/rancher/rio) at [cli/cmd/images/image.go](https://github.com/rancher/rio/blob/e9d490246e7252a04eb872a99f542c5da2f135cf/cli/cmd/images/image.go#L60-L129)
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 pod used in defer or goroutine at line 64
[Click here to see the code in its original context.](https://github.com/rancher/rio/blob/e9d490246e7252a04eb872a99f542c5da2f135cf/cli/cmd/images/image.go#L60-L129)
Click here to show the 70 line(s) of Go which triggered the analyzer.
```go
for _, pod := range pods.Items {
if strings.HasPrefix(pod.Name, constants.BuildkitdService) {
readyChan := make(chan struct{})
go func() {
if err := localbuilder.PortForward(ctx.RestConfig, ctx.K8s, portForward, registryPort, pod, false, readyChan, localbuilder.ChanWrapper(ctx.Ctx.Done())); err != nil {
logrus.Fatal(err)
}
}()
select {
case <-readyChan:
break
}
var result []Image
resp, err := http.Get(fmt.Sprintf("%s:%s/v2/_catalog", registryAPIURL, portForward))
if err != nil {
return err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
catalog := catalog{}
if err := json.Unmarshal(data, &catalog); err != nil {
return err
}
for _, repo := range catalog.Repositories {
resp, err = http.Get(fmt.Sprintf("%s:%s/v2/%s/tags/list", registryAPIURL, portForward, repo))
if err != nil {
return err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
repo := repository{}
if err := json.Unmarshal(data, &repo); err != nil {
return err
}
for _, tag := range repo.Tags {
namespace, name := kv.Split(repo.Name, "/")
if namespace != ctx.GetSetNamespace() {
continue
}
result = append(result, Image{
Namespace: namespace,
Repo: name,
Tag: tag,
Image: fmt.Sprintf("localhost:5442/%s:%s", repo.Name, tag),
})
}
}
writer := tables.NewImage(ctx)
defer writer.TableWriter().Close()
for _, obj := range result {
writer.TableWriter().Write(obj)
}
return writer.TableWriter().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: e9d490246e7252a04eb872a99f542c5da2f135cf
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.