From e4ca72be0a591a5b441d110d102dbcee88206f1b Mon Sep 17 00:00:00 2001 From: Shalabh Gupta <83173695+coding-shalabh@users.noreply.github.com> Date: Mon, 9 Mar 2026 12:25:28 +0530 Subject: [PATCH] fix: use defer for file handle cleanup in readDirNames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the file handle was closed explicitly after calling Readdirnames(-1). This approach has two issues: 1. If Readdirnames() panics, the file handle is never closed (resource leak) 2. The explicit Close() doesn't follow Go best practices Changed to use 'defer f.Close()' immediately after successful Open(), ensuring the file handle is always closed when the function exits, regardless of the execution path. This follows the standard Go idiom for resource cleanup and prevents potential file handle leaks in edge cases. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 0d1be128..cbd92f3b 100644 --- a/config/config.go +++ b/config/config.go @@ -406,9 +406,9 @@ func readDirNames(path string) ([]string, error) { if err != nil { return nil, err } + defer f.Close() paths, err := f.Readdirnames(-1) - f.Close() if err != nil { return nil, err }