diff templates/classic/detectors/__init__.py @ 1786:7752267776cc

fixed file leak in detector initialisation (patch [SF#800715])
author Richard Jones <richard@users.sourceforge.net>
date Thu, 04 Sep 2003 23:44:56 +0000
parents 91dc06940bbe
children 461d8aa81376
line wrap: on
line diff
--- a/templates/classic/detectors/__init__.py	Thu Sep 04 23:39:18 2003 +0000
+++ b/templates/classic/detectors/__init__.py	Thu Sep 04 23:44:56 2003 +0000
@@ -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 @@
     ''' 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

Roundup Issue Tracker: http://roundup-tracker.org/