Skip to content
vetkitChecksChangelogDocumentation

vetkit.go.quality.defer-in-loop

defer inside a loop runs only when the surrounding function returns, not at the end of each iteration. Resources such as files or locks pile up until then.

Last updated:

Suite: Code quality

go

defer inside a loop runs only when the surrounding function returns, not at the end of each iteration. Resources such as files or locks pile up until then.

Category: QUALITY · Engine rule severity: WARNING

How to fix it

Move the loop body into a helper function (or closure) so the deferred call runs per iteration, or release the resource explicitly.

References

Source: packages/engine/rules/quality/go.yml.

Generated from shipped rule definitions at build time. Matching is a review signal, not proof of exploitability. “generic” denotes text matching, not complete language or framework coverage. Runtime configuration and available tools affect whether a rule runs.