Skip to content

Commit b353b10

Browse files
committed
fix: check pprof.StartCPUProfile error in --cpuprofile debug flag
golangci-lint (errcheck) flags the unchecked error; return it and close the profile file if profiling cannot start.
1 parent 7dd56c1 commit b353b10

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

internal/cli/root.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,20 @@ func NewRootCmd() *cobra.Command {
7272
return err
7373
}
7474
profFile = f
75-
pprof.StartCPUProfile(f)
75+
if err := pprof.StartCPUProfile(f); err != nil {
76+
_ = f.Close()
77+
profFile = nil
78+
return err
79+
}
7680
return nil
7781
}
7882
root.PersistentPostRunE = func(cmd *cobra.Command, args []string) error {
7983
if profFile != nil {
8084
pprof.StopCPUProfile()
81-
profFile.Close()
85+
if err := profFile.Close(); err != nil {
86+
profFile = nil
87+
return err
88+
}
8289
profFile = nil
8390
}
8491
return nil

0 commit comments

Comments
 (0)