From 03f34d1158614fdeed700539d20b223a57688e3c Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Wed, 2 Nov 2005 05:43:19 +0000 Subject: Backport (with cleanup): Bug #1344508, Fix UNIX mmap leaking file descriptors. --- Misc/NEWS | 2 ++ Modules/mmapmodule.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index c22d598..ae962c9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -25,6 +25,8 @@ Core and builtins Extension Modules ----------------- +- Bug #1344508, Fix UNIX mmap leaking file descriptors + - Patch #1338314, Bug #1336623: fix tarfile so it can extract REGTYPE directories from tarfiles written by old programs. diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 4d781bb..db24e46 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -99,6 +99,8 @@ mmap_object_dealloc(mmap_object *m_obj) #endif /* MS_WINDOWS */ #ifdef UNIX + if (m_obj->fd >= 0) + (void) close(m_obj->fd); if (m_obj->data!=NULL) { msync(m_obj->data, m_obj->size, MS_SYNC); munmap(m_obj->data, m_obj->size); @@ -136,6 +138,8 @@ mmap_close_method(mmap_object *self, PyObject *args) #endif /* MS_WINDOWS */ #ifdef UNIX + (void) close(self->fd); + self->fd = -1; if (self->data != NULL) { munmap(self->data, self->size); self->data = NULL; -- cgit v0.12