diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2020-11-07 08:54:50 +0100 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2020-11-07 09:35:02 +0100 |
commit | dd378ee46082862f711629d40ed33f944d1e3259 (patch) | |
tree | 4cf8e3f30f534cf4bc481d5eb1bb8977fe940d1f /giscanner/cachestore.py | |
parent | 5f966b0b8d61e2abf003439b2f93a9bd19be798c (diff) | |
download | gobject-introspection-dd378ee46082862f711629d40ed33f944d1e3259.tar.gz |
Always close files
This means flushing changes and closing the fd. Otherwise this is done
by the GC eventually..
Detected using PYTHONTRACEMALLOC=1 PYTHONDEVMODE=1
Diffstat (limited to 'giscanner/cachestore.py')
-rw-r--r-- | giscanner/cachestore.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py index e3b76058..3512badc 100644 --- a/giscanner/cachestore.py +++ b/giscanner/cachestore.py @@ -169,12 +169,14 @@ class CacheStore(object): return None else: raise - if not self._cache_is_valid(store_filename, filename): - return None - try: - data = pickle.load(fd) - except Exception: - # Broken cache entry, remove it - self._remove_filename(store_filename) - data = None - return data + + with fd: + if not self._cache_is_valid(store_filename, filename): + return None + try: + data = pickle.load(fd) + except Exception: + # Broken cache entry, remove it + self._remove_filename(store_filename) + data = None + return data |