Fix file descriptor leak when FileResponse raises an exception
This commit is contained in:
parent
4c4203f335
commit
4a6391730d
1 changed files with 8 additions and 3 deletions
|
|
@ -23,9 +23,14 @@ class MediaAccess(View):
|
|||
raise Http404
|
||||
if not os.path.isfile(file_path):
|
||||
raise Http404
|
||||
response = FileResponse(open(file_path, 'rb'))
|
||||
response['Cache-Control'] = 'max-age=2678400'
|
||||
return response
|
||||
f = open(file_path, 'rb')
|
||||
try:
|
||||
response = FileResponse(f)
|
||||
response['Cache-Control'] = 'max-age=2678400'
|
||||
return response
|
||||
except Exception:
|
||||
f.close()
|
||||
raise
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, ListView):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue