From c0d41249eed232cc97197890f20e3f7a36bf43d3 Mon Sep 17 00:00:00 2001 From: Oleksii Leonov Date: Fri, 6 Nov 2026 13:58:17 +0000 Subject: [PATCH] Close files inspected by LineEndings LineEndings opens every inspected file without explicitly closing it. Large commits and whole-repository checks can exhaust file descriptors before garbage collection runs, including in other concurrent hooks. Use a File.open block so each file closes after validation. Keep the encoding-warning handler inside the block so it can still read the file's line number before the file closes. --- lib/overcommit/hook/pre_commit/line_endings.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/overcommit/hook/pre_commit/line_endings.rb b/lib/overcommit/hook/pre_commit/line_endings.rb index ab66001b..95b7cbbb 100644 --- a/lib/overcommit/hook/pre_commit/line_endings.rb +++ b/lib/overcommit/hook/pre_commit/line_endings.rb @@ -9,8 +9,7 @@ def run messages = [] offending_files.map do |file_name| - file = File.open(file_name) - begin + File.open(file_name) do |file| messages += check_file(file, file_name) rescue ArgumentError => e # File is likely a binary file which this check should ignore, but