[ python-Bugs-1402308 ] segfault when using mmap(-1,...) [+PATCH]

SourceForge.net noreply at sourceforge.net
Wed Jan 11 09:43:36 CET 2006


Bugs item #1402308, was opened at 2006-01-11 00:38
Message generated for change (Comment added) made by titty
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: Open
Resolution: None
Priority: 5
Submitted By: Ralf Schmitt (titty)
Assigned to: Nobody/Anonymous (nobody)
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: Ralf Schmitt (titty)
Date: 2006-01-11 08: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