summaryrefslogtreecommitdiffstats
path: root/Lib/dbm
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-04 08:01:02 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-04 08:01:02 (GMT)
commit46ba6c8563922f043cad6423202ee0119614c807 (patch)
tree4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/dbm
parentae2d667ae83548029fed7244619fadd7f625cb24 (diff)
downloadcpython-46ba6c8563922f043cad6423202ee0119614c807.zip
cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.gz
cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.bz2
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/dbm')
-rw-r--r--Lib/dbm/__init__.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/dbm/__init__.py b/Lib/dbm/__init__.py
index 5f4664a..6831a84 100644
--- a/Lib/dbm/__init__.py
+++ b/Lib/dbm/__init__.py
@@ -153,9 +153,9 @@ def whichdb(filename):
except OSError:
return None
- # Read the start of the file -- the magic number
- s16 = f.read(16)
- f.close()
+ with f:
+ # Read the start of the file -- the magic number
+ s16 = f.read(16)
s = s16[0:4]
# Return "" if not at least 4 bytes