aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2019-12-23 15:59:11 -0500
committerJake Hunsaker <jhunsake@redhat.com>2020-01-09 13:20:12 -0500
commita5828cc806cc8a5b89aaac808ed1e8c7a60fa941 (patch)
tree47b862d535957d19db5dd3f7ce0b27d06157c533
parent2224137c2b6e7931f2bb8bb8c48c414a7fa023f1 (diff)
downloadsos-a5828cc806cc8a5b89aaac808ed1e8c7a60fa941.tar.gz
[Policy] Wrap json.load() in with clause
Wraps `json.load()` from preset loading in a `with` statement to ensure that file objects are properly closed. Closes: #1322 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/policies/__init__.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index d004e9f2..651abc6c 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -768,10 +768,11 @@ any third party.
for preset_path in os.listdir(presets_path):
preset_path = os.path.join(presets_path, preset_path)
- try:
- preset_data = json.load(open(preset_path))
- except ValueError:
- continue
+ with open(preset_path) as pf:
+ try:
+ preset_data = json.load(pf)
+ except ValueError:
+ continue
for preset in preset_data.keys():
pd = PresetDefaults(preset, opts=SoSOptions())