Skip to content

Commit

Permalink
Ensure config file is closed in case of exceptions
Browse files Browse the repository at this point in the history
Address code-QL findings.

Signed-off-by: Nicola Sirena <[email protected]>
  • Loading branch information
NSsirena committed Oct 23, 2023
1 parent 2a465f6 commit cb724dd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
path = os.path.join(os.path.dirname(__file__), fname)
with open(path, "r") as file:
return file.read()


console_scripts = [
Expand Down
3 changes: 2 additions & 1 deletion src/slurm_plugin/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def _get_config(self, config_file_path):

config = ConfigParser()
try:
config.read_file(open(config_file_path, "r"))
with open(config_file_path, "r") as config_file:
config.read_file(config_file)
except IOError:
log.error("Cannot read slurm cloud bursting scripts configuration file: %s", config_file_path)
raise
Expand Down
3 changes: 2 additions & 1 deletion src/slurm_plugin/suspend.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class SlurmSuspendConfig:
def __init__(self, config_file_path):
config = ConfigParser()
try:
config.read_file(open(config_file_path, "r"))
with open(config_file_path, "r") as config_file:
config.read_file(config_file)
except IOError:
log.error("Cannot read slurm cloud bursting scripts configuration file: %s", config_file_path)
raise
Expand Down

0 comments on commit cb724dd

Please sign in to comment.