Issue #7732: Fix a crash on importing a module if a directory has the same name
than a Python module (e.g. "__init__.py"): don't close the file twice.
PyFile_FromFile() does also close the file if PyString_FromString() failed. It
did already close the file on fill_file_fields() error (e.g. if the file is a
directory).
diff --git a/Python/import.c b/Python/import.c
index 673d1b3..c60ecfe 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2845,10 +2845,8 @@
return NULL;
if (fp != NULL) {
fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose);
- if (fob == NULL) {
- fclose(fp);
+ if (fob == NULL)
return NULL;
- }
}
else {
fob = Py_None;