diff --git a/Misc/NEWS b/Misc/NEWS index 24018acf4a6..dcc2b81e8d3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -56,6 +56,9 @@ Core and Builtins Library ------- +- Issue #6271: mmap tried to close invalid file handle (-1) when annonymous. + (On Unix) + - Issue #6258: Support AMD64 in bdist_msi. - Issue #5262: Fixed bug in next rollover time computation in diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index cbacc2fc252..1d0f490d5ab 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -158,7 +158,8 @@ mmap_close_method(mmap_object *self, PyObject *unused) #endif /* MS_WINDOWS */ #ifdef UNIX - (void) close(self->fd); + if (0 <= self->fd) + (void) close(self->fd); self->fd = -1; if (self->data != NULL) { munmap(self->data, self->size);