summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Cardona <remi.cardona@logilab.fr>2015-09-18 15:00:15 +0200
committerRémi Cardona <remi.cardona@logilab.fr>2015-09-18 15:00:15 +0200
commit93275d9f0a049c1a80a0f6dfcc5adbc330dba928 (patch)
tree9acc0ca1eee4a2dd4923c27cb64bfad7ef4716de
parent14847732ef7e853ef659634dbed2b8da9cc35c5e (diff)
downloadlogilab-common-93275d9f0a049c1a80a0f6dfcc5adbc330dba928.tar.gz
[modutils] Fix fd leak in load_module_from_modpath
-rw-r--r--logilab/common/modutils.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/logilab/common/modutils.py b/logilab/common/modutils.py
index dd725d2..e70a1a9 100644
--- a/logilab/common/modutils.py
+++ b/logilab/common/modutils.py
@@ -165,7 +165,11 @@ def load_module_from_modpath(parts, path=None, use_sys=True):
module = sys.modules.get(curname)
if module is None:
mp_file, mp_filename, mp_desc = find_module(part, path)
- module = load_module(curname, mp_file, mp_filename, mp_desc)
+ try:
+ module = load_module(curname, mp_file, mp_filename, mp_desc)
+ finally:
+ if mp_file is not None:
+ mp_file.close()
if prevmodule:
setattr(prevmodule, part, module)
_file = getattr(module, '__file__', '')