github-vet / rangeloop-pointer-findings

Issue tracker collects instances of Go code on GitHub that make use of references to range loop variables.
0 stars 0 forks source link

Grenfis/omxweb: omxremote.go; 27 LoC #3783

Open githubvet opened 3 years ago

githubvet commented 3 years ago

Found a possible issue in Grenfis/omxweb at omxremote.go

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 k used in defer or goroutine at line 319

Click here to see the code in its original context.

Click here to show the 27 line(s) of Go which triggered the analyzer. ```go for k, v := range commands { go func(key, name string) { defer wg.Done() args := strings.Split(name, " ") out := bytes.NewBuffer(nil) cmd := exec.Command(args[0], args[1:]...) cmd.Stdout = out cmd.Stderr = out if err := cmd.Run(); err != nil { log.Println("Failed to execute command", k, err) lock.Lock() output[key] = "N/A" lock.Unlock() return } lock.Lock() output[key] = strings.TrimSpace(out.String()) lock.Unlock() }(k, v) } ```

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 for more information.

commit ID: 6410a027a9d18987f878cbcd5a83e05ecc5d5138

mdempsky commented 3 years ago

They tried to mitigate the issue, but then still accidentally referred to k in the log.Println call.