Skip to content

Commit 53a1d02

Browse files
author
Richard Jones
committed
fixed file leak in detector initialisation (patch [SF#800715])
1 parent 34f04fd commit 53a1d02

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ are given with the most recent entry first.
55
Fixed:
66
- cleaned up, clarified internal caching API in *dbm backends
77
- stopped pyc writing to current directory! yay! (patch 800718 with changes)
8+
- fixed file leak in detector initialisation (patch 800715)
89
- commented out example tracker homes (patch 800720)
910

1011

templates/classic/detectors/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: __init__.py,v 1.2 2003-09-04 23:39:18 richard Exp $
18+
#$Id: __init__.py,v 1.3 2003-09-04 23:44:56 richard Exp $
1919

2020
import sys, os, imp
2121

2222
def init(db):
2323
''' execute the init functions of all the modules in this directory
2424
'''
2525
this_dir = os.path.split(__file__)[0]
26-
for file in os.listdir(this_dir):
27-
path = os.path.join(this_dir, file)
28-
name, ext = os.path.splitext(file)
26+
for filename in os.listdir(this_dir):
27+
name, ext = os.path.splitext(filename)
2928
if name == '__init__':
3029
continue
3130
if ext == '.py':
32-
module = imp.load_module(name, open(path), os.path.abspath(path),
33-
('.py', 'r', imp.PY_SOURCE))
31+
path = os.path.abspath(os.path.join(this_dir, filename))
32+
fp = open(path)
33+
try:
34+
module = imp.load_module(name, open(path), path,
35+
('.py', 'r', imp.PY_SOURCE))
36+
finally:
37+
fp.close()
3438
module.init(db)
3539

3640
# vim: set filetype=python ts=4 sw=4 et si

templates/minimal/detectors/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: __init__.py,v 1.2 2003-09-04 23:39:18 richard Exp $
18+
#$Id: __init__.py,v 1.3 2003-09-04 23:44:56 richard Exp $
1919

2020
import sys, os, imp
2121

2222
def init(db):
2323
''' execute the init functions of all the modules in this directory
2424
'''
2525
this_dir = os.path.split(__file__)[0]
26-
for file in os.listdir(this_dir):
27-
path = os.path.join(this_dir, file)
28-
name, ext = os.path.splitext(file)
26+
for filename in os.listdir(this_dir):
27+
name, ext = os.path.splitext(filename)
2928
if name == '__init__':
3029
continue
3130
if ext == '.py':
32-
module = imp.load_module(name, open(path), os.path.abspath(path),
33-
('.py', 'r', imp.PY_SOURCE))
34-
print (name, open(path), file, module)
31+
path = os.path.abspath(os.path.join(this_dir, filename))
32+
fp = open(path)
33+
try:
34+
module = imp.load_module(name, open(path), path,
35+
('.py', 'r', imp.PY_SOURCE))
36+
finally:
37+
fp.close()
3538
module.init(db)
3639

3740
# vim: set filetype=python ts=4 sw=4 et si

0 commit comments

Comments
 (0)