elastic / elastic/elastic-agent-libs

global variable 'cpuOut' is always nil

Open
#61 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6
Forks
57
Avg merge
6d 7h
Merged PRs (30d)
3

Description

```
package service

...
var cpuOut *os.File
...

// BeforeRun takes care of necessary actions such as creating files
// before the beat should run.
func BeforeRun() {
logger := logp.NewLogger("service")
if withCPUProfile() {
cpuOut, err := os.Create(*cpuprofile)
....
}

...
}
```

`cpuOut, err := os.Create(*cpuprofile)` will create a new variable `cpuOut`, which is different with global variable `var cpuOut *os.File`. Global variable `var cpuOut *os.File` is never set and one error will be created when function `Cleanup()` is called.

```
func Cleanup() {
logger := logp.NewLogger("service")
if withCPUProfile() {
pprof.StopCPUProfile()
cpuOut.Close() // -------- cpuOut is nil
}

...
}
```
Besides, the `cpuprofile` will not be closed in time.

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.