diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-05 14:21:12 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-05 14:21:12 (GMT) |
commit | 264fc12fbff471d137f61e5fd7152f5a7df9eb6c (patch) | |
tree | 4b8c2c1496a7b81bcee8245000c3f3f7af914478 /Modules/mmapmodule.c | |
parent | a3e6c9763c475a93ab5fab0a42b2b3718e196d93 (diff) | |
download | cpython-264fc12fbff471d137f61e5fd7152f5a7df9eb6c.zip cpython-264fc12fbff471d137f61e5fd7152f5a7df9eb6c.tar.gz cpython-264fc12fbff471d137f61e5fd7152f5a7df9eb6c.tar.bz2 |
Issue #5385: Fixed mmap crash after resize failure on windows.
Now uses NULL instead of INVALID_HANDLE_VALUE as invalid map handle
because CreateFileMapping returns NULL when error occurs.
Diffstat (limited to 'Modules/mmapmodule.c')
-rw-r--r-- | Modules/mmapmodule.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index ca5fa88..95dcfbe 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -112,7 +112,7 @@ mmap_object_dealloc(mmap_object *m_obj) #ifdef MS_WINDOWS if (m_obj->data != NULL) UnmapViewOfFile (m_obj->data); - if (m_obj->map_handle != INVALID_HANDLE_VALUE) + if (m_obj->map_handle != NULL) CloseHandle (m_obj->map_handle); if (m_obj->file_handle != INVALID_HANDLE_VALUE) CloseHandle (m_obj->file_handle); @@ -147,9 +147,9 @@ mmap_close_method(mmap_object *self, PyObject *unused) UnmapViewOfFile(self->data); self->data = NULL; } - if (self->map_handle != INVALID_HANDLE_VALUE) { + if (self->map_handle != NULL) { CloseHandle(self->map_handle); - self->map_handle = INVALID_HANDLE_VALUE; + self->map_handle = NULL; } if (self->file_handle != INVALID_HANDLE_VALUE) { CloseHandle(self->file_handle); @@ -173,7 +173,7 @@ mmap_close_method(mmap_object *self, PyObject *unused) #ifdef MS_WINDOWS #define CHECK_VALID(err) \ do { \ - if (self->map_handle == INVALID_HANDLE_VALUE) { \ + if (self->map_handle == NULL) { \ PyErr_SetString(PyExc_ValueError, "mmap closed or invalid"); \ return err; \ } \ @@ -441,8 +441,10 @@ mmap_resize_method(mmap_object *self, DWORD off_hi, off_lo, newSizeLow, newSizeHigh; /* First, unmap the file view */ UnmapViewOfFile(self->data); + self->data = NULL; /* Close the mapping object */ CloseHandle(self->map_handle); + self->map_handle = NULL; /* Move to the desired EOF position */ #if SIZEOF_SIZE_T > 4 newSizeHigh = (DWORD)((self->offset + new_size) >> 32); @@ -479,6 +481,8 @@ mmap_resize_method(mmap_object *self, return Py_None; } else { dwErrCode = GetLastError(); + CloseHandle(self->map_handle); + self->map_handle = NULL; } } else { dwErrCode = GetLastError(); @@ -1279,7 +1283,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) destruct the object in the face of failure */ m_obj->data = NULL; m_obj->file_handle = INVALID_HANDLE_VALUE; - m_obj->map_handle = INVALID_HANDLE_VALUE; + m_obj->map_handle = NULL; m_obj->tagname = NULL; m_obj->offset = offset; @@ -1376,8 +1380,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) m_obj->size); if (m_obj->data != NULL) return (PyObject *)m_obj; - else + else { dwErr = GetLastError(); + CloseHandle(m_obj->map_handle); + m_obj->map_handle = NULL; + } } else dwErr = GetLastError(); Py_DECREF(m_obj); |