From a5828cc806cc8a5b89aaac808ed1e8c7a60fa941 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Mon, 23 Dec 2019 15:59:11 -0500 Subject: [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 --- sos/policies/__init__.py | 9 +++++---- 1 file 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()) -- cgit