Skip to content

False positive G307: Deferring unsafe method "Close" on type "*os.File" (gosec) linting error #97

@atc0005

Description

@atc0005

This linting error was surfaced from an upgraded golangci-lint:

internal/lockss/load.go:81:2: G307: Deferring unsafe method "Close" on type "*os.File" (gosec)
	defer func() {
		if err := f.Close(); err != nil {
			logger.Printf(
				"Error occurred closing file %q: %v\n",
				filename,
				err,
			)
		}
	}()
internal/lockss/load.go:290:2: G307: Deferring unsafe method "Close" on type "*os.File" (gosec)
	defer func() {
		if err := f.Close(); err != nil {
			// Ignore "file already closed" errors
			if !errors.Is(err, os.ErrClosed) {
				logger.Printf(
					"%s: failed to close file %q: %s",
					myFuncName,
					cleanFilename,
					err.Error(),
				)
			}
		}
	}()
make: *** [Makefile:114: linting] Error 1
Error: Process completed with exit code 2.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglinting

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions