github-vet / github-vet/rangeloop-pointer-findings

gurupras/go_cpuprof: post_processing/temp_battery_correlation_new.go; 31 LoC

Open
#15,047 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [gurupras/go_cpuprof](https://www.github.com/gurupras/go_cpuprof) at [post_processing/temp_battery_correlation_new.go](https://github.com/gurupras/go_cpuprof/blob/75cef0a86b8d92bb1b151d1269c2981c2d5a0238/post_processing/temp_battery_correlation_new.go#L71-L101)

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 filePath used in defer or goroutine at line 78

[Click here to see the code in its original context.](https://github.com/gurupras/go_cpuprof/blob/75cef0a86b8d92bb1b151d1269c2981c2d5a0238/post_processing/temp_battery_correlation_new.go#L71-L101)

Click here to show the 31 line(s) of Go which triggered the analyzer.

```go
for _, filePath := range files {
wg.Add(1)
sem.P()
go func() {
defer wg.Done()
defer sem.V()
buf := new(bytes.Buffer)
if file, err = os.OpenFile(filePath, os.O_RDONLY, 0444); err != nil {
err = errors.New(fmt.Sprintf("Failed to open file: %v - %v", filePath, err))
return
}
if gzipReader, err = gzip.NewReader(file); err != nil {
err = errors.New(fmt.Sprintf("Failed to get gzip reader to: %v - %v", filePath, err))
return
}
if _, err = io.Copy(buf, gzipReader); err != nil {
err = errors.New(fmt.Sprintf("Failed to copy bytes from gzipReader: %v", err))
return
}
tbcChunk := new(TbcChunk)
if err = json.Unmarshal(buf.Bytes(), tbcChunk); err != nil {
err = errors.New(fmt.Sprintf("Failed to unmarshal file: %v - %v", filePath, err))
return
}
mutex.Lock()
idx++
//fmt.Println(fmt.Sprintf("Processed %d chunks", idx))
mutex.Unlock()
channel <- tbcChunk
}()
}

```

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: 75cef0a86b8d92bb1b151d1269c2981c2d5a0238

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.