Skip to content

Commit

Permalink
Close fileobj in case of error. (Closes: #7)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lamb <chris@chris-lamb.co.uk>
  • Loading branch information
giampaolo authored and lamby committed Jul 25, 2018
1 parent 6777cc7 commit 16f1069
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fadvise/__init__.py
Expand Up @@ -105,6 +105,10 @@ def _open_wrapper(advice, *args, **kwargs):

fileobj = open(*args, **kwargs)

set_advice(fileobj, advice, offset=offset, len=len)
try:
set_advice(fileobj, advice, offset=offset, len=len)
except Exception:
fileobj.close()
raise

return fileobj

0 comments on commit 16f1069

Please sign in to comment.