github-vet / github-vet/rangeloop-pointer-findings
lsowen/cam-record: main.go; 74 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [lsowen/cam-record](https://www.github.com/lsowen/cam-record) at [main.go](https://github.com/lsowen/cam-record/blob/ca231ad1ec21e0456fc6db740013bcd62ef56a87/main.go#L51-L124)
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 pkt used in defer or goroutine at line 86
[Click here to see the code in its original context.](https://github.com/lsowen/cam-record/blob/ca231ad1ec21e0456fc6db740013bcd62ef56a87/main.go#L51-L124)
Click here to show the 74 line(s) of Go which triggered the analyzer.
```go
for pkt := range commandChan {
if url, ok := config.Cameras[pkt.CameraId]; ok {
if pkt.Command == START_RECORDING {
if _, ok := currentProcs[pkt.CameraId]; !ok {
filename := time.Now().UTC().Format("2006-01-02-15-04-05") + "_" + pkt.CameraId + "_" + uuid.New() + ".webm"
saveLocation := config.SavePath + filename
options := []string{
"-e",
"rtspsrc",
"location=" + url,
"!",
"rtph264depay",
"!",
"avdec_h264",
"!",
"queue",
"!",
"vp8enc",
"deadline=100",
"!",
"webmmux",
"!",
"filesink",
"location=" + saveLocation,
}
cmd := exec.Command("gst-launch-1.0", options...)
if err := cmd.Start(); err == nil {
currentProcs[pkt.CameraId] = RecordingEntry{
Process: cmd.Process,
Filename: saveLocation,
}
if config.Scripts.RecordStart != "" {
go func() {
exec.Command(config.Scripts.RecordStart, pkt.CameraId, saveLocation).Run()
}()
}
} else {
fmt.Println(err)
}
}
}
if pkt.Command == STOP_RECORDING {
if entry, ok := currentProcs[pkt.CameraId]; ok {
go func(config Configuration, pkt CommandPacket, entry RecordingEntry) {
entry.Process.Signal(os.Interrupt)
entry.Process.Wait()
if config.Scripts.RecordEnd != "" {
go func() {
exec.Command(config.Scripts.RecordEnd, pkt.CameraId, entry.Filename).Run()
}()
}
}(config, pkt, entry)
delete(currentProcs, pkt.CameraId)
}
}
if pkt.Command == GET_STATUS {
if _, ok := currentProcs[pkt.CameraId]; ok {
pkt.StatusChan <- StatusPacket{
Status: STATUS_RECORDING,
}
} else {
pkt.StatusChan <- StatusPacket{
Status: STATUS_NOTRECORDING,
}
}
close(pkt.StatusChan)
}
}
}
```
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: ca231ad1ec21e0456fc6db740013bcd62ef56a87
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with main.go lines 51-124 and inspect the goroutines that use the range-loop variable pkt, especially the record-start and record-end callbacks. Determine whether the analyzer warning represents a real issue in this context, then classify the finding as Bug, Mitigated, or Desirable Behavior using the linked project guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100