diff --git a/Misc/NEWS b/Misc/NEWS index 9ed8b16b93f..407681b3d65 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -15,6 +15,9 @@ Core and Builtins Library ------- +- Issue #6271: mmap tried to close invalid file handle (-1) when annonymous. + (On Unix) + What's New in Python 3.1 Release Candidate 2? ============================================= diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index fd247abd56b..37584e22255 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -164,7 +164,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);