Mercurial > cpython-lru_cache-weakref
comparison Python/import.c @ 75177:fcd0a67e708e
Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Wed, 22 Feb 2012 18:08:30 +0100 |
| parents | e12b8d3a3d03 cbfd2bf80db0 |
| children | 72556ff86828 |
comparison
equal
deleted
inserted
replaced
| 75174:ac4256a1fbe6 | 75177:fcd0a67e708e |
|---|---|
| 3626 if (fp != NULL) { | 3626 if (fp != NULL) { |
| 3627 fd = fileno(fp); | 3627 fd = fileno(fp); |
| 3628 if (fd != -1) | 3628 if (fd != -1) |
| 3629 fd = dup(fd); | 3629 fd = dup(fd); |
| 3630 fclose(fp); | 3630 fclose(fp); |
| 3631 if (fd == -1) { | |
| 3632 PyErr_SetFromErrno(PyExc_OSError); | |
| 3633 return NULL; | |
| 3634 } | |
| 3635 fp = NULL; | 3631 fp = NULL; |
| 3632 if (fd == -1) | |
| 3633 return PyErr_SetFromErrno(PyExc_OSError); | |
| 3636 } | 3634 } |
| 3637 if (fd != -1) { | 3635 if (fd != -1) { |
| 3638 if (strchr(fdp->mode, 'b') == NULL) { | 3636 if (strchr(fdp->mode, 'b') == NULL) { |
| 3639 /* PyTokenizer_FindEncodingFilename() returns PyMem_MALLOC'ed | 3637 /* PyTokenizer_FindEncodingFilename() returns PyMem_MALLOC'ed |
| 3640 memory. */ | 3638 memory. */ |
| 3641 found_encoding = PyTokenizer_FindEncodingFilename(fd, pathobj); | 3639 found_encoding = PyTokenizer_FindEncodingFilename(fd, pathobj); |
| 3642 lseek(fd, 0, 0); /* Reset position */ | 3640 lseek(fd, 0, 0); /* Reset position */ |
| 3643 if (found_encoding == NULL && PyErr_Occurred()) { | 3641 if (found_encoding == NULL && PyErr_Occurred()) { |
| 3644 Py_XDECREF(pathobj); | 3642 Py_XDECREF(pathobj); |
| 3643 close(fd); | |
| 3645 return NULL; | 3644 return NULL; |
| 3646 } | 3645 } |
| 3647 encoding = (found_encoding != NULL) ? found_encoding : | 3646 encoding = (found_encoding != NULL) ? found_encoding : |
| 3648 (char*)PyUnicode_GetDefaultEncoding(); | 3647 (char*)PyUnicode_GetDefaultEncoding(); |
| 3649 } | 3648 } |
