Skip to content

Commit

Permalink
Close file in SanitizedFile#mime_magic_content_type
Browse files Browse the repository at this point in the history
Fixes bug where file handles are being left open. This was introduced in #1934
and #1936
  • Loading branch information
Owen Davies authored and mshibuya committed Apr 30, 2019
1 parent 22b3ce9 commit af3aba9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/carrierwave/sanitized_file.rb
Expand Up @@ -341,7 +341,11 @@ def existing_content_type
end

def mime_magic_content_type
MimeMagic.by_magic(File.open(path)).try(:type) || 'invalid/invalid' if path
if path
File.open(path) do |file|
MimeMagic.by_magic(file).try(:type) || 'invalid/invalid'
end
end
rescue Errno::ENOENT
nil
end
Expand Down

0 comments on commit af3aba9

Please sign in to comment.