cleanup: address golangci 'errcheck' issues

Many reports are about closing or removing files. In some cases it is
possible to report an error in the logs, in other cases the error can be
ignored without potential issues.

Test cases have been modified to not remove the temporary files. The
temporary directory that is provided by the testing package, is removed
once the tests are done.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2025-05-02 17:33:29 +02:00
committed by mergify[bot]
parent 0a22e3a186
commit bc8b1e792f
19 changed files with 131 additions and 71 deletions

View File

@ -45,7 +45,7 @@ func getCgroupPidsFile() (string, error) {
if err != nil {
return "", err
}
defer cgroup.Close() // #nosec: error on close is not critical here
defer cgroup.Close() //nolint:errcheck,nosec // error on close is not critical here
pidsMax := ""
scanner := bufio.NewScanner(cgroup)
@ -88,7 +88,7 @@ func GetPIDLimit() (int, error) {
if err != nil {
return 0, err
}
defer f.Close() // #nosec: error on close is not critical here
defer f.Close() //nolint:errcheck,nosec // error on close is not critical here
maxPidsStr, err := bufio.NewReader(f).ReadString('\n')
if err != nil && !errors.Is(err, io.EOF) {
@ -128,7 +128,7 @@ func SetPIDLimit(limit int) error {
_, err = f.WriteString(limitStr)
if err != nil {
f.Close() // #nosec: a write error will be more useful to return
f.Close() //nolint:errcheck,gosec // a write error will be more useful to return
return err
}