diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:43:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:43:02 (GMT) |
commit | 91b0bc237c07b52c771e121098989680cfc3600d (patch) | |
tree | 96ce4b2c32292bf2f619846c1599c9af0142f2f7 /Lib/http/server.py | |
parent | 933209689e8d07e3ce00c68ca26e001b130f0b62 (diff) | |
download | cpython-91b0bc237c07b52c771e121098989680cfc3600d.zip cpython-91b0bc237c07b52c771e121098989680cfc3600d.tar.gz cpython-91b0bc237c07b52c771e121098989680cfc3600d.tar.bz2 |
Issue #20331: Fixed possible FD leaks in various modules:
http.server, imghdr, mailcap, mimetypes, xml.etree.
Diffstat (limited to 'Lib/http/server.py')
-rw-r--r-- | Lib/http/server.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py index 7050b95..dab1eb6 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -670,8 +670,10 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): """Serve a GET request.""" f = self.send_head() if f: - self.copyfile(f, self.wfile) - f.close() + try: + self.copyfile(f, self.wfile) + finally: + f.close() def do_HEAD(self): """Serve a HEAD request.""" @@ -712,13 +714,17 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): except IOError: self.send_error(404, "File not found") return None - self.send_response(200) - self.send_header("Content-type", ctype) - fs = os.fstat(f.fileno()) - self.send_header("Content-Length", str(fs[6])) - self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) - self.end_headers() - return f + try: + self.send_response(200) + self.send_header("Content-type", ctype) + fs = os.fstat(f.fileno()) + self.send_header("Content-Length", str(fs[6])) + self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) + self.end_headers() + return f + except: + f.close() + raise def list_directory(self, path): """Helper to produce a directory listing (absent index.html). |