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