github-vet / github-vet/rangeloop-pointer-findings
GodSlave/MyGoServer: mqtt/service/process.go; 45 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [GodSlave/MyGoServer](https://www.github.com/GodSlave/MyGoServer) at [mqtt/service/process.go](https://github.com/GodSlave/MyGoServer/blob/0de8c0309f84815481f286b882d49d56de8ab8ed/mqtt/service/process.go#L314-L358)
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 t used in defer or goroutine at line 328
[Click here to see the code in its original context.](https://github.com/GodSlave/MyGoServer/blob/0de8c0309f84815481f286b882d49d56de8ab8ed/mqtt/service/process.go#L314-L358)
Click here to show the 45 line(s) of Go which triggered the analyzer.
```go
for i, t := range topics {
//if t[0] == 'i' || t[0] == 'f' {
// //TODO verify userModule
// if len(this.sess.AesKey) == 0 {
// log.Info("subscribe with error topic id %s", t)
// retcodes = append(retcodes, 0x80)
// }
//} else
//
if t[0] == 's' {
defer func() {
if err == nil {
pubMessage := message.NewPublishMessage()
pubMessage.SetTopic(t)
randBytes := make([]byte, 32)
uuid.RandBytes(randBytes)
pubMessage.SetPayload(randBytes)
err := this.PublishMsg(pubMessage)
if err == nil {
md5result := base.GetMd5T([]byte(this.sess.Id), randBytes)
this.sess.AesKey = md5result[:]
log.Info("AesKey is %v", md5result)
} else {
log.Error(err.Error())
}
} else {
log.Error(" ` random code error %s", err.Error())
}
}()
}
rqos, err := this.topicsMgr.Subscribe(t, qos[i], &this.onpub)
if err != nil {
return err
}
this.sess.AddTopic(string(t), qos[i])
retcodes = append(retcodes, rqos)
// yeah I am not checking errors here. If there's an error we don't want the
// subscription to stop, just let it go.
this.topicsMgr.Retained(t, &this.rmsgs)
log.Debug("(%s) topic = %s, retained count = %d", this.cid(), string(t), len(this.rmsgs))
}
```
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: 0de8c0309f84815481f286b882d49d56de8ab8ed
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.