Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
atc0005 opened this issue Nov 9, 2021 · 0 comments · Fixed by #98
Assignees
Labels
bug Something isn't working linting
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Nov 9, 2021

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.
@atc0005 atc0005 added bug Something isn't working linting labels Nov 9, 2021
@atc0005 atc0005 added this to the Next Release milestone Nov 9, 2021
@atc0005 atc0005 self-assigned this Nov 9, 2021
atc0005 added a commit that referenced this issue Nov 9, 2021
Issues reported after upgrading golangci-lint to v1.43.0.
gosec was updated in that version from v2.8.1 to v2.9.1.

refs #97
refs golangci/golangci-lint#2299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant