comparison Python/import.c @ 75176:cbfd2bf80db0 3.2

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:05:43 +0100
parents 963a0fba98e0
children daed636a3536 fcd0a67e708e
comparison
equal deleted inserted replaced
75175:963a0fba98e0 75176:cbfd2bf80db0
3193 if (strchr(fdp->mode, 'b') == NULL) { 3193 if (strchr(fdp->mode, 'b') == NULL) {
3194 /* PyTokenizer_FindEncoding() returns PyMem_MALLOC'ed 3194 /* PyTokenizer_FindEncoding() returns PyMem_MALLOC'ed
3195 memory. */ 3195 memory. */
3196 found_encoding = PyTokenizer_FindEncoding(fd); 3196 found_encoding = PyTokenizer_FindEncoding(fd);
3197 lseek(fd, 0, 0); /* Reset position */ 3197 lseek(fd, 0, 0); /* Reset position */
3198 if (found_encoding == NULL && PyErr_Occurred()) 3198 if (found_encoding == NULL && PyErr_Occurred()) {
3199 close(fd);
3199 return NULL; 3200 return NULL;
3201 }
3200 encoding = (found_encoding != NULL) ? found_encoding : 3202 encoding = (found_encoding != NULL) ? found_encoding :
3201 (char*)PyUnicode_GetDefaultEncoding(); 3203 (char*)PyUnicode_GetDefaultEncoding();
3202 } 3204 }
3203 fob = PyFile_FromFd(fd, pathname, fdp->mode, -1, 3205 fob = PyFile_FromFd(fd, pathname, fdp->mode, -1,
3204 (char*)encoding, NULL, NULL, 1); 3206 (char*)encoding, NULL, NULL, 1);