mirror of
https://github.com/slackhq/nebula.git
synced 2026-03-11 01:01:57 -07:00
fix: use defer for file handle cleanup in readDirNames
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 <noreply@anthropic.com>
This commit is contained in:
parent
7760ccefba
commit
e4ca72be0a
1 changed files with 1 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue