From 09931787c14b02588a862146395a2cbf77ff0bc0 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 13 Aug 2019 11:58:20 +0200 Subject: [PATCH] config: do not leak file descriptor when reading config Makes sure that the config file descriptor is closed once read. --- datadog/util/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/datadog/util/config.py b/datadog/util/config.py index 7241265c8..0c2069fd8 100644 --- a/datadog/util/config.py +++ b/datadog/util/config.py @@ -113,7 +113,8 @@ def get_config(cfg_path=None, options=None): config_path = get_config_path(cfg_path, os_name=get_os()) config = configparser.ConfigParser() - config.readfp(skip_leading_wsp(open(config_path))) + with open(config_path) as config_file: + config.readfp(skip_leading_wsp(config_file)) # bulk import for option in config.options('Main'):