summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-02-22 17:05:43 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-02-22 17:05:43 (GMT)
commit4f22a8d739494d188ba0b4430ca86d93e1ed30d2 (patch)
tree542690d3f7d727e26758953e3dc7747215d9ae68 /Python/import.c
parent72146124432fd9372032de1a3a508236ea4ab0d4 (diff)
downloadcpython-4f22a8d739494d188ba0b4430ca86d93e1ed30d2.zip
cpython-4f22a8d739494d188ba0b4430ca86d93e1ed30d2.tar.gz
cpython-4f22a8d739494d188ba0b4430ca86d93e1ed30d2.tar.bz2
Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c
index e5581c5..f443ab8 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -3195,8 +3195,10 @@ call_find_module(char *name, PyObject *path)
memory. */
found_encoding = PyTokenizer_FindEncoding(fd);
lseek(fd, 0, 0); /* Reset position */
- if (found_encoding == NULL && PyErr_Occurred())
+ if (found_encoding == NULL && PyErr_Occurred()) {
+ close(fd);
return NULL;
+ }
encoding = (found_encoding != NULL) ? found_encoding :
(char*)PyUnicode_GetDefaultEncoding();
}