github-vet / github-vet/rangeloop-pointer-findings
Ra1nyHouse/iforest: iforest.go; 19 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [Ra1nyHouse/iforest](https://www.github.com/Ra1nyHouse/iforest) at [iforest.go](https://github.com/Ra1nyHouse/iforest/blob/8ab1a1da2d0d3fd07b9b4a892d838751d89cf4dd/iforest.go#L162-L180)
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 row used in defer or goroutine at line 166
[Click here to see the code in its original context.](https://github.com/Ra1nyHouse/iforest/blob/8ab1a1da2d0d3fd07b9b4a892d838751d89cf4dd/iforest.go#L162-L180)
Click here to show the 19 line(s) of Go which triggered the analyzer.
```go
for _, row := range rows {
for _, node := range f.roots {
// 在树的粒度上并行
go func(_node *Node) {
ch <- _path(row, _node, 0, rand.New(rand.NewSource(int64(_node.TreeSeed))))
}(node)
// 一定要注意协程不要引用局部变量,下面会导致BUG,node 几乎是同一个
//go func(rSeed int) {
// ch <- _path(row, node, 0, rand.New(rand.NewSource(int64(rSeed))))
//}(node.TreeSeed)
}
score := float32(0)
for i := 0; i < len(f.roots); i++ {
score += <-ch
}
score = score / float32(len(f.roots))
scores = append(scores, score)
}
```
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: 8ab1a1da2d0d3fd07b9b4a892d838751d89cf4dd
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.