github-vet / github-vet/rangeloop-pointer-findings
janelia-flyem/dvid: datatype/labelmap/equiv.go; 73 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [janelia-flyem/dvid](https://www.github.com/janelia-flyem/dvid) at [datatype/labelmap/equiv.go](https://github.com/janelia-flyem/dvid/blob/cb4620e65a3cc57fa038c6242abc01b0873f0299/datatype/labelmap/equiv.go#L187-L259)
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 ancestor used in defer or goroutine at line 207
[Click here to see the code in its original context.](https://github.com/janelia-flyem/dvid/blob/cb4620e65a3cc57fa038c6242abc01b0873f0299/datatype/labelmap/equiv.go#L187-L259)
Click here to show the 73 line(s) of Go which triggered the analyzer.
```go
for _, ancestor := range ancestors {
vid, found := svm.versions[ancestor]
if found {
return nil // we have already loaded this version and its ancestors
}
vid, err = svm.createShortVersion(ancestor)
if err != nil {
return fmt.Errorf("problem creating mapping version for id %d: %v", ancestor, err)
}
timedLog := dvid.NewTimeLog()
ch := make(chan storage.LogMessage, 100)
wg := new(sync.WaitGroup)
go func(vid uint8, ch chan storage.LogMessage, wg *sync.WaitGroup) {
numMsgs := 0
for msg := range ch { // expects channel to be closed on completion
numMsgs++
switch msg.EntryType {
case proto.MappingOpType:
var op proto.MappingOp
if err := op.Unmarshal(msg.Data); err != nil {
dvid.Errorf("unable to unmarshal mapping log message for version %d: %v\n", ancestor, err)
wg.Done()
continue
}
mapped := op.GetMapped()
for _, supervoxel := range op.GetOriginal() {
svm.setMapping(vid, supervoxel, mapped)
}
case proto.SplitOpType:
var op proto.SplitOp
if err := op.Unmarshal(msg.Data); err != nil {
dvid.Errorf("unable to unmarshal split log message for version %d: %v\n", ancestor, err)
wg.Done()
continue
}
splits := svm.splits[vid]
for supervoxel, svsplit := range op.GetSvsplits() {
rec := proto.SupervoxelSplitOp{
Mutid: op.Mutid,
Supervoxel: supervoxel,
Remainlabel: svsplit.Remainlabel,
Splitlabel: svsplit.Splitlabel,
}
splits = append(splits, rec)
svm.setMapping(vid, supervoxel, 0)
}
svm.splits[vid] = splits
case proto.SupervoxelSplitType:
var op proto.SupervoxelSplitOp
if err := op.Unmarshal(msg.Data); err != nil {
dvid.Errorf("unable to unmarshal split log message for version %d: %v\n", ancestor, err)
wg.Done()
continue
}
rec := proto.SupervoxelSplitOp{
Mutid: op.Mutid,
Supervoxel: op.Supervoxel,
Remainlabel: op.Remainlabel,
Splitlabel: op.Splitlabel,
}
svm.splits[vid] = append(svm.splits[vid], rec)
svm.setMapping(vid, op.Supervoxel, 0)
default:
}
wg.Done()
}
}(vid, ch, wg)
if err = labels.StreamLog(d, ancestor, ch, wg); err != nil {
return fmt.Errorf("problem loading mapping logs: %v", err)
}
wg.Wait()
timedLog.Infof("Loaded mappings for data %q, version ID %d", d.DataName(), ancestor)
}
```
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: cb4620e65a3cc57fa038c6242abc01b0873f0299
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.