diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-23 12:38:48 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-23 12:38:48 -0400 |
commit | d5722c5cdc1986fc3c430989f3e31007a518bc3b (patch) | |
tree | 55f3fd0a4f0062abbe805b2ae6bbcdd041c328e3 | |
parent | 9466b308b1488d1e0ea3af2f3913955e60cb28e9 (diff) | |
download | python-coveragepy-d5722c5cdc1986fc3c430989f3e31007a518bc3b.tar.gz |
Be sure to close the file we opened if something goes wrong.
-rw-r--r-- | coverage/data.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/coverage/data.py b/coverage/data.py index 26fee48..704a348 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -238,9 +238,13 @@ class CoverageData(object): def _open_for_reading(cls, filename): """Open a file appropriately for reading data.""" f = open(filename, "r") - go_away = f.read(len(cls.GO_AWAY)) - if go_away != cls.GO_AWAY: - raise CoverageException("Doesn't seem to be a coverage.py data file") + try: + go_away = f.read(len(cls.GO_AWAY)) + if go_away != cls.GO_AWAY: + raise CoverageException("Doesn't seem to be a coverage.py data file") + except Exception: + f.close() + raise return f @classmethod |