From e50e61b2c39ff82df36620c23c126f62dcb04e19 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 15 Apr 2016 14:43:56 +0200 Subject: core.actions: explicitly close file descriptor Thanks to Ale1ster for pointing it out. Fixes #529 --- ranger/core/actions.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 3b1fc47a..ab97d81c 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -343,18 +343,19 @@ class Actions(FileManagerAware, SettingsAware): Load a config file. """ filename = os.path.expanduser(filename) - for line in open(filename, 'r'): - line = line.lstrip().rstrip("\r\n") - if line.startswith("#") or not line.strip(): - continue - try: - self.execute_console(line) - except Exception as e: - if ranger.arg.debug: - raise - else: - self.notify('Error in line `%s\':\n %s' % - (line, str(e)), bad=True) + with open(filename, 'r') as f: + for line in f: + line = line.lstrip().rstrip("\r\n") + if line.startswith("#") or not line.strip(): + continue + try: + self.execute_console(line) + except Exception as e: + if ranger.arg.debug: + raise + else: + self.notify('Error in line `%s\':\n %s' % + (line, str(e)), bad=True) def execute_file(self, files, **kw): """Uses the "rifle" module to open/execute a file -- cgit 1.4.1-2-gfad0