summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2003-01-10 20:52:16 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2003-01-10 20:52:16 (GMT)
commite604c02a803f075efecb318f5fb584faf7bf12c4 (patch)
treeb6565e57f8c5610323528b299feb4bd379e8e9b9
parente7a161e60ceb5ca24752404683802f49afe18e8c (diff)
downloadcpython-e604c02a803f075efecb318f5fb584faf7bf12c4.zip
cpython-e604c02a803f075efecb318f5fb584faf7bf12c4.tar.gz
cpython-e604c02a803f075efecb318f5fb584faf7bf12c4.tar.bz2
SF #665913, Fix mmap module core dump with unix
Closing an mmap'ed file (calling munmap) twice on Solaris caused a core dump. Will backport.
-rw-r--r--Lib/test/test_mmap.py18
-rw-r--r--Modules/mmapmodule.c6
2 files changed, 22 insertions, 2 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 417080f..69d3cd5 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -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'
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index cff3c14..f1df4dc 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -141,8 +141,10 @@ mmap_close_method(mmap_object *self, PyObject *args)
#endif /* MS_WINDOWS */
#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);