cpython: 2766320bdb10 (original) (raw)
Mercurial > cpython
changeset 88702:2766320bdb10 3.3
Issue #20331: Fixed possible FD leaks in various modules: http.server, imghdr, mailcap, mimetypes, xml.etree. [#20331]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Sat, 25 Jan 2014 19:43:02 +0200 |
parents | 900a1ff323bb |
children | b30e57756686 035ab711b8cc |
files | Lib/http/server.py Lib/imghdr.py Lib/mailcap.py Lib/mimetypes.py Lib/xml/etree/ElementInclude.py |
diffstat | 5 files changed, 34 insertions(+), 30 deletions(-)[+] [-] Lib/http/server.py 24 Lib/imghdr.py 20 Lib/mailcap.py 4 Lib/mimetypes.py 7 Lib/xml/etree/ElementInclude.py 9 |
line wrap: on
line diff
--- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -670,8 +670,10 @@ class SimpleHTTPRequestHandler(BaseHTTPR """Serve a GET request.""" f = self.send_head() if f:
self.copyfile(f, self.wfile)[](#l1.7)
f.close()[](#l1.8)
try:[](#l1.9)
self.copyfile(f, self.wfile)[](#l1.10)
finally:[](#l1.11)
f.close()[](#l1.12)
def do_HEAD(self): """Serve a HEAD request.""" @@ -712,13 +714,17 @@ class SimpleHTTPRequestHandler(BaseHTTPR except IOError: self.send_error(404, "File not found") return None
self.send_response(200)[](#l1.20)
self.send_header("Content-type", ctype)[](#l1.21)
fs = os.fstat(f.fileno())[](#l1.22)
self.send_header("Content-Length", str(fs[6]))[](#l1.23)
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))[](#l1.24)
self.end_headers()[](#l1.25)
return f[](#l1.26)
try:[](#l1.27)
self.send_response(200)[](#l1.28)
self.send_header("Content-type", ctype)[](#l1.29)
fs = os.fstat(f.fileno())[](#l1.30)
self.send_header("Content-Length", str(fs[6]))[](#l1.31)
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))[](#l1.32)
self.end_headers()[](#l1.33)
return f[](#l1.34)
except:[](#l1.35)
f.close()[](#l1.36)
raise[](#l1.37)
def list_directory(self, path): """Helper to produce a directory listing (absent index.html).
--- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -7,18 +7,16 @@ #-------------------------# def what(file, h=None):
- if h is None:
if isinstance(file, str):[](#l2.8)
f = open(file, 'rb')[](#l2.9)
h = f.read(32)[](#l2.10)
else:[](#l2.11)
location = file.tell()[](#l2.12)
h = file.read(32)[](#l2.13)
file.seek(location)[](#l2.14)
f = None[](#l2.15)
- else:
f = None[](#l2.17)
- f = None try:
if h is None:[](#l2.20)
if isinstance(file, str):[](#l2.21)
f = open(file, 'rb')[](#l2.22)
h = f.read(32)[](#l2.23)
else:[](#l2.24)
location = file.tell()[](#l2.25)
h = file.read(32)[](#l2.26)
file.seek(location)[](#l2.27) for tf in tests:[](#l2.28) res = tf(h, f)[](#l2.29) if res:[](#l2.30)
--- a/Lib/mailcap.py +++ b/Lib/mailcap.py @@ -22,8 +22,8 @@ def getcaps(): fp = open(mailcap, 'r') except IOError: continue
morecaps = readmailcapfile(fp)[](#l3.7)
fp.close()[](#l3.8)
with fp:[](#l3.9)
morecaps = readmailcapfile(fp)[](#l3.10) for key, value in morecaps.items():[](#l3.11) if not key in caps:[](#l3.12) caps[key] = value[](#l3.13)
--- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -363,9 +363,10 @@ def read_mime_types(file): f = open(file) except IOError: return None
--- a/Lib/xml/etree/ElementInclude.py +++ b/Lib/xml/etree/ElementInclude.py @@ -76,14 +76,13 @@ class FatalIncludeError(SyntaxError): def default_loader(href, parse, encoding=None): if parse == "xml":
file = open(href, 'rb')[](#l5.7)
data = ElementTree.parse(file).getroot()[](#l5.8)