Skip to content

Commit

Permalink
don't leak file descriptor (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
crepererum authored and criemen committed Oct 22, 2018
1 parent 83b817a commit e2860ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
*********

Next
====

* Fix file-descriptor leak in `KeyValueStore._get_file`

0.11.10
=======

Expand Down
15 changes: 9 additions & 6 deletions simplekv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ def _get_file(self, key, file):
# this allows us to support file-like objects without close as well,
# such as BytesIO.
source = self.open(key)
while True:
buf = source.read(bufsize)
file.write(buf)

if len(buf) < bufsize:
break
try:
while True:
buf = source.read(bufsize)
file.write(buf)

if len(buf) < bufsize:
break
finally:
source.close()

def _get_filename(self, key, filename):
"""Write key to file. Either this method or
Expand Down

0 comments on commit e2860ea

Please sign in to comment.