]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 10 Jan 2003 21:02:41 +0000 (21:02 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 10 Jan 2003 21:02:41 +0000 (21:02 +0000)
SF #665913, Fix mmap module core dump with unix

Closing an mmap'ed file (calling munmap) twice on Solaris caused a core dump.

Lib/test/test_mmap.py
Misc/NEWS
Modules/mmapmodule.c

index 417080f0055efe1ac05b9a264a0204571482ab4d..69d3cd5311f544165837907ee818b78c022d9ff2 100644 (file)
@@ -297,6 +297,24 @@ def test_both():
         except OSError:
             pass
 
+    # make sure a double close doesn't crash on Solaris (Bug# 665913)
+    f = open(TESTFN, 'w+')
+
+    try:    # unlink TESTFN no matter what
+        f.write(2**24 * 'a') # Arbitrary character
+        f.close()
+
+        f = open(TESTFN)
+        mf = mmap.mmap(f.fileno(), 2**24, access=mmap.ACCESS_READ)
+        mf.close()
+        mf.close()
+        f.close()
+
+    finally:
+        try:
+            os.unlink(TESTFN)
+        except OSError:
+            pass
 
 
     print ' Test passed'
index f77ebbd1d6aae6a809de0a283e0de3156ec3c40c..9cd93ae688d6dade257e8f7dd99a812e4089b979 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -51,6 +51,8 @@ Release date: XX-XXX-2003
 
 - New codec for Ukrainian Cyrillic.
 
+- SF #665913: fix crash on Solaris when closing an mmap'ed file which
+  was already closed.
 
 What's New in Python 2.2.2 (final) ?
 Release date: 14-Oct-2002
index cabb8600869ecd8b6b8be2ce834660fa6b289e04..9af90c19c93d5078e9ac47015d333014f7de157b 100644 (file)
@@ -141,8 +141,10 @@ mmap_close_method(mmap_object *self, PyObject *args)
 #endif /* MS_WIN32 */
 
 #ifdef UNIX
-       munmap(self->data, self->size);
-       self->data = NULL;
+       if (self->data != NULL) {
+               munmap(self->data, self->size);
+               self->data = NULL;
+       }
 #endif
 
        Py_INCREF (Py_None);