[ python-Bugs-1402308 ] segfault when using mmap(-1,...) [+PATCH]
SourceForge.net
noreply at sourceforge.net
Sat Jan 14 08:40:22 CET 2006
Bugs item #1402308, was opened at 2006-01-10 16:38
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1402308&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Ralf Schmitt (titty)
>Assigned to: Neal Norwitz (nnorwitz)
Summary: segfault when using mmap(-1,...) [+PATCH]
Initial Comment:
This is happening on OSX, Python 2.4.2:
ralf at mini:~/Python-2.4.2$ cat ~/t.py
#! /usr/bin/env python
import sys
print sys.version
import mmap
mmap.mmap(-1, 4096)
ralf at mini:~/Python-2.4.2$ ./python ~/t.py
2.4.2 (#1, Jan 11 2006, 00:58:35)
[GCC 4.0.1 (Apple Computer, Inc. build 5247)]
Segmentation fault
The following one line diff solves that problem (mmap's data member
is otherwise uninitialized...)
ralf at mini:~/Python-2.4.2$ diff -u Modules/mmapmodule.c-orig
Modules/mmapmodule.c--- Modules/mmapmodule.c-orig
2006-01-11 01:12:32.000000000 +0100
+++ Modules/mmapmodule.c 2006-01-11 01:13:06.000000000
+0100
@@ -910,6 +910,7 @@
#endif
m_obj = PyObject_New (mmap_object, &mmap_object_type);
if (m_obj == NULL) {return NULL;}
+ m_obj->data = NULL;
m_obj->size = (size_t) map_size;
m_obj->pos = (size_t) 0;
m_obj->fd = dup(fd);
However, the problem is that passing -1 as filedescriptor to mmap
is perfectly ok when one wants to mmap anonymous memory (at least
on FreeeBSD and OS X). The following patch also solves that problem.
[mmap.mmap(-1, 4096, mmap.MAP_ANON) now works...]
Any chance to get this included? Passing -1 to mmap should not hurt
anybody, as systems which do not support it, should then return an
error from mmap.
ralf at mini:~/Python-2.4.2$ diff -u Modules/mmapmodule.c-orig
Modules/mmapmodule.c--- Modules/mmapmodule.c-orig
2006-01-11 01:12:32.000000000 +0100
+++ Modules/mmapmodule.c 2006-01-11 01:23:52.000000000
+0100
@@ -910,10 +910,12 @@
#endif
m_obj = PyObject_New (mmap_object, &mmap_object_type);
if (m_obj == NULL) {return NULL;}
+ m_obj->data = NULL;
m_obj->size = (size_t) map_size;
m_obj->pos = (size_t) 0;
- m_obj->fd = dup(fd);
- if (m_obj->fd == -1) {
+ if (fd == -1) {
+ m_obj->fd = -1;
+ } else if ((m_obj->fd = dup(fd)) == -1) {
Py_DECREF(m_obj);
PyErr_SetFromErrno(mmap_module_error);
return NULL;
----------------------------------------------------------------------
>Comment By: Neal Norwitz (nnorwitz)
Date: 2006-01-13 23:40
Message:
Logged In: YES
user_id=33168
Thanks. I only fixed the bug as the second part is a
feature request.
Committed revision 42012.
Committed revision 42041. (2.4)
I'm not opposed to adding the feature, but would like to
keep the unix and windows versions as similar as possible.
I don't know what windows does in this case. I'm going to
close this bug report.
If you are interested in making a patch that handles
windows, unix, and the doc feel free to submit a patch for
it. Also, when you submit a patch please attach a file
since SF screws up the formatting. For the one-liner it's
not a big deal to inline, but it could be a problem for
python code still.
----------------------------------------------------------------------
Comment By: Ralf Schmitt (titty)
Date: 2006-01-11 00:43
Message:
Logged In: YES
user_id=17929
this is a regression from 2.4.1. On 2.4.1 mmap(-1, 4096,
mmap.MAP_ANON) works without problems.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1402308&group_id=5470
More information about the Python-bugs-list
mailing list