Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

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

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

Comments

@atc0005
Copy link
Owner

atc0005 commented Nov 30, 2021

These linting errors were surfaced from an upgraded golangci-lint:

activefile/activefile.go:141: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) {
				ezproxy.Logger.Printf(
					"filterEntries: failed to close file %q: %s",
					afr.Filename,
					err.Error(),
				)
			}
		}
	}()
auditlog/auditlog.go:164: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) {
				ezproxy.Logger.Printf(
					"AllSessionEntries: failed to close file %q: %s",
					alr.Filename,
					err.Error(),
				)
			}
		}
	}()
make: *** [Makefile:67: linting] Error 1
@atc0005 atc0005 added bug Something isn't working linting labels Nov 30, 2021
@atc0005 atc0005 added this to the Next Release milestone Nov 30, 2021
@atc0005 atc0005 self-assigned this Nov 30, 2021
atc0005 added a commit that referenced this issue Nov 30, 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 GH-70
refs golangci/golangci-lint#2299
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working linting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant