From f6d65dd1b2ff3ed4cc9e68bdf581ef6643b14c71 Mon Sep 17 00:00:00 2001 From: Owen Davies Date: Mon, 11 Jul 2016 15:03:21 +0100 Subject: [PATCH] Close file in SanitizedFile#mime_magic_content_type Fixes bug where file handles are being left open. This was introduced in #1934 and #1936 --- lib/carrierwave/sanitized_file.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/sanitized_file.rb b/lib/carrierwave/sanitized_file.rb index 8ad6b6d5f..543344ae3 100644 --- a/lib/carrierwave/sanitized_file.rb +++ b/lib/carrierwave/sanitized_file.rb @@ -315,7 +315,11 @@ def existing_content_type end def mime_magic_content_type - MimeMagic.by_magic(File.open(path)).try(:type) if path + if path + File.open(path) do |file| + MimeMagic.by_magic(file).try(:type) + end + end rescue Errno::ENOENT nil end