FIX: Properly close file descriptor 9 in trap handler

Added explicit file descriptor close (exec 9>&-) in trap handler to prevent
file descriptor leaks. While bash cleans up FDs on exit, explicit closure
is proper practice and prevents potential issues in long-running processes.

Changes:
- trap handler now: flock -u 9; exec 9>&-; rm -f; cleanup
- Ensures FD 9 is explicitly closed before process exit

Impact:
- Prevents potential FD exhaustion in edge cases
- Follows bash best practices
- Zero functional impact

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
cschantz
2026-03-02 22:15:53 -05:00
parent 231888a2e8
commit db64d9cbc3
@@ -375,7 +375,7 @@ get_wp_sites_cached() {
# Cleanup on exit (keep cache file for next invocation, only remove lock file) # Cleanup on exit (keep cache file for next invocation, only remove lock file)
# CRITICAL: Must unlock flock (fd 9) before removing lock file! # CRITICAL: Must unlock flock (fd 9) before removing lock file!
trap 'flock -u 9 2>/dev/null; rm -f "$LOCK_FILE"; rollback_cleanup' EXIT INT TERM trap 'flock -u 9 2>/dev/null; exec 9>&-; rm -f "$LOCK_FILE"; rollback_cleanup' EXIT INT TERM
# OPTIMIZATION: User extraction caching (memoization) # OPTIMIZATION: User extraction caching (memoization)
# extract_user_from_path() called 10 times, often for same path # extract_user_from_path() called 10 times, often for same path