github-vet / github-vet/rangeloop-pointer-findings
containers/virtcontainers: api.go; 42 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [containers/virtcontainers](https://www.github.com/containers/virtcontainers) at [api.go](https://github.com/containers/virtcontainers/blob/0c8079c9ad6b95f573b8a0af8e6cf8418fc35fd5/api.go#L529-L570)
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 container used in defer or goroutine at line 554
[Click here to see the code in its original context.](https://github.com/containers/virtcontainers/blob/0c8079c9ad6b95f573b8a0af8e6cf8418fc35fd5/api.go#L529-L570)
Click here to show the 42 line(s) of Go which triggered the analyzer.
```go
for _, container := range pod.containers {
if container.id == containerID {
// We have to check for the process state to make sure
// we update the status in case the process is supposed
// to be running but has been killed or terminated.
if (container.state.State == StateReady ||
container.state.State == StateRunning ||
container.state.State == StatePaused) &&
container.process.Pid > 0 {
running, err := isShimRunning(container.process.Pid)
if err != nil {
return ContainerStatus{}, err
}
if !running {
pod.wg.Add(1)
go func() {
defer pod.wg.Done()
lockFile, err := rwLockPod(pod.id)
if err != nil {
return
}
defer unlockPod(lockFile)
if err := container.stop(); err != nil {
return
}
}()
}
}
return ContainerStatus{
ID: container.id,
State: container.state,
PID: container.process.Pid,
StartTime: container.process.StartTime,
RootFs: container.config.RootFs,
Annotations: container.config.Annotations,
}, nil
}
}
```
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: 0c8079c9ad6b95f573b8a0af8e6cf8418fc35fd5
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.