diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-01-28 09:49:29 +0100 |
---|---|---|
committer | Pavel Moravec <pmoravec@redhat.com> | 2020-01-28 09:52:39 +0100 |
commit | f867f783d333679ad871c77b473bd4e6a258ab4a (patch) | |
tree | 6fd57bcb52f14844262b4f1c8efdddcf97abd389 | |
parent | f6645b43e6f46611696049cc28481d2522cfe259 (diff) | |
parent | a5828cc806cc8a5b89aaac808ed1e8c7a60fa941 (diff) | |
download | sos-f867f783d333679ad871c77b473bd4e6a258ab4a.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>
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r-- | sos/policies/__init__.py | 9 |
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()) |