]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport (with cleanup): Bug #1344508, Fix UNIX mmap leaking file descriptors.
authorNeal Norwitz <nnorwitz@gmail.com>
Wed, 2 Nov 2005 05:43:19 +0000 (05:43 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Wed, 2 Nov 2005 05:43:19 +0000 (05:43 +0000)
Misc/NEWS
Modules/mmapmodule.c

index c22d598c406d1658229599cf7535b15c5d5cf34d..ae962c9227f70168bc8e5b50669fb561be3422ee 100644 (file)
--- 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.
 
index 4d781bbef3fed0dc8a20050cbfb21aae5a89f80d..db24e46d6a5f99cdf5ba9671095cf2fd206994ed 100644 (file)
@@ -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;