Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
91b0bc23
Commit
91b0bc23
authored
Jan 25, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20331: Fixed possible FD leaks in various modules:
http.server, imghdr, mailcap, mimetypes, xml.etree.
parent
93320968
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
30 deletions
+34
-30
Lib/http/server.py
Lib/http/server.py
+15
-9
Lib/imghdr.py
Lib/imghdr.py
+9
-11
Lib/mailcap.py
Lib/mailcap.py
+2
-2
Lib/mimetypes.py
Lib/mimetypes.py
+4
-3
Lib/xml/etree/ElementInclude.py
Lib/xml/etree/ElementInclude.py
+4
-5
No files found.
Lib/http/server.py
View file @
91b0bc23
...
...
@@ -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).
...
...
Lib/imghdr.py
View file @
91b0bc23
...
...
@@ -7,18 +7,16 @@ __all__ = ["what"]
#-------------------------#
def
what
(
file
,
h
=
None
):
if
h
is
None
:
if
isinstance
(
file
,
str
):
f
=
open
(
file
,
'rb'
)
h
=
f
.
read
(
32
)
else
:
location
=
file
.
tell
()
h
=
file
.
read
(
32
)
file
.
seek
(
location
)
f
=
None
else
:
f
=
None
f
=
None
try
:
if
h
is
None
:
if
isinstance
(
file
,
str
):
f
=
open
(
file
,
'rb'
)
h
=
f
.
read
(
32
)
else
:
location
=
file
.
tell
()
h
=
file
.
read
(
32
)
file
.
seek
(
location
)
for
tf
in
tests
:
res
=
tf
(
h
,
f
)
if
res
:
...
...
Lib/mailcap.py
View file @
91b0bc23
...
...
@@ -22,8 +22,8 @@ def getcaps():
fp
=
open
(
mailcap
,
'r'
)
except
IOError
:
continue
morecaps
=
readmailcapfile
(
fp
)
fp
.
close
(
)
with
fp
:
morecaps
=
readmailcapfile
(
fp
)
for
key
,
value
in
morecaps
.
items
():
if
not
key
in
caps
:
caps
[
key
]
=
value
...
...
Lib/mimetypes.py
View file @
91b0bc23
...
...
@@ -363,9 +363,10 @@ def read_mime_types(file):
f
=
open
(
file
)
except
IOError
:
return
None
db
=
MimeTypes
()
db
.
readfp
(
f
,
True
)
return
db
.
types_map
[
True
]
with
f
:
db
=
MimeTypes
()
db
.
readfp
(
f
,
True
)
return
db
.
types_map
[
True
]
def
_default_mime_types
():
...
...
Lib/xml/etree/ElementInclude.py
View file @
91b0bc23
...
...
@@ -76,14 +76,13 @@ class FatalIncludeError(SyntaxError):
def
default_loader
(
href
,
parse
,
encoding
=
None
):
if
parse
==
"xml"
:
file
=
open
(
href
,
'rb'
)
data
=
ElementTree
.
parse
(
file
).
getroot
()
with
open
(
href
,
'rb'
)
as
file
:
data
=
ElementTree
.
parse
(
file
).
getroot
()
else
:
if
not
encoding
:
encoding
=
'UTF-8'
file
=
open
(
href
,
'r'
,
encoding
=
encoding
)
data
=
file
.
read
()
file
.
close
()
with
open
(
href
,
'r'
,
encoding
=
encoding
)
as
file
:
data
=
file
.
read
()
return
data
##
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment