From e811029f3fb3558afde95d090c78a45dcf196490 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 4 Sep 2003 23:44:56 +0000 Subject: [PATCH] fixed file leak in detector initialisation (patch 800715) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1853 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 1 + templates/classic/detectors/__init__.py | 16 ++++++++++------ templates/minimal/detectors/__init__.py | 17 ++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 39f9a80..f31aa91 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ are given with the most recent entry first. Fixed: - cleaned up, clarified internal caching API in *dbm backends - stopped pyc writing to current directory! yay! (patch 800718 with changes) +- fixed file leak in detector initialisation (patch 800715) - commented out example tracker homes (patch 800720) diff --git a/templates/classic/detectors/__init__.py b/templates/classic/detectors/__init__.py index a9460a0..518d343 100644 --- a/templates/classic/detectors/__init__.py +++ b/templates/classic/detectors/__init__.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: __init__.py,v 1.2 2003-09-04 23:39:18 richard Exp $ +#$Id: __init__.py,v 1.3 2003-09-04 23:44:56 richard Exp $ import sys, os, imp @@ -23,14 +23,18 @@ def init(db): ''' execute the init functions of all the modules in this directory ''' this_dir = os.path.split(__file__)[0] - for file in os.listdir(this_dir): - path = os.path.join(this_dir, file) - name, ext = os.path.splitext(file) + for filename in os.listdir(this_dir): + name, ext = os.path.splitext(filename) if name == '__init__': continue if ext == '.py': - module = imp.load_module(name, open(path), os.path.abspath(path), - ('.py', 'r', imp.PY_SOURCE)) + path = os.path.abspath(os.path.join(this_dir, filename)) + fp = open(path) + try: + module = imp.load_module(name, open(path), path, + ('.py', 'r', imp.PY_SOURCE)) + finally: + fp.close() module.init(db) # vim: set filetype=python ts=4 sw=4 et si diff --git a/templates/minimal/detectors/__init__.py b/templates/minimal/detectors/__init__.py index 859a22c..518d343 100644 --- a/templates/minimal/detectors/__init__.py +++ b/templates/minimal/detectors/__init__.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: __init__.py,v 1.2 2003-09-04 23:39:18 richard Exp $ +#$Id: __init__.py,v 1.3 2003-09-04 23:44:56 richard Exp $ import sys, os, imp @@ -23,15 +23,18 @@ def init(db): ''' execute the init functions of all the modules in this directory ''' this_dir = os.path.split(__file__)[0] - for file in os.listdir(this_dir): - path = os.path.join(this_dir, file) - name, ext = os.path.splitext(file) + for filename in os.listdir(this_dir): + name, ext = os.path.splitext(filename) if name == '__init__': continue if ext == '.py': - module = imp.load_module(name, open(path), os.path.abspath(path), - ('.py', 'r', imp.PY_SOURCE)) - print (name, open(path), file, module) + path = os.path.abspath(os.path.join(this_dir, filename)) + fp = open(path) + try: + module = imp.load_module(name, open(path), path, + ('.py', 'r', imp.PY_SOURCE)) + finally: + fp.close() module.init(db) # vim: set filetype=python ts=4 sw=4 et si -- 2.30.2