diff options
-rw-r--r-- | Modules/mmapmodule.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 8e5a0bd..6bde993 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -227,6 +227,14 @@ do { \ return err; \ } \ } while (0) +#define CHECK_VALID_OR_RELEASE(err, buffer) \ +do { \ + if (self->map_handle == NULL) { \ + PyErr_SetString(PyExc_ValueError, "mmap closed or invalid"); \ + PyBuffer_Release(&(buffer)); \ + return (err); \ + } \ +} while (0) #endif /* MS_WINDOWS */ #ifdef UNIX @@ -237,6 +245,14 @@ do { \ return err; \ } \ } while (0) +#define CHECK_VALID_OR_RELEASE(err, buffer) \ +do { \ + if (self->data == NULL) { \ + PyErr_SetString(PyExc_ValueError, "mmap closed or invalid"); \ + PyBuffer_Release(&(buffer)); \ + return (err); \ + } \ +} while (0) #endif /* UNIX */ static PyObject * @@ -326,7 +342,7 @@ mmap_gfind(mmap_object *self, end = self->size; Py_ssize_t res; - CHECK_VALID(NULL); + CHECK_VALID_OR_RELEASE(NULL, view); if (reverse) { res = _PyBytes_ReverseFind( self->data + start, end - start, @@ -403,7 +419,7 @@ mmap_write_method(mmap_object *self, return NULL; } - CHECK_VALID(NULL); + CHECK_VALID_OR_RELEASE(NULL, data); memcpy(&self->data[self->pos], data.buf, data.len); self->pos += data.len; PyBuffer_Release(&data); @@ -1087,7 +1103,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value) return -1; } - CHECK_VALID(-1); + CHECK_VALID_OR_RELEASE(-1, vbuf); if (slicelen == 0) { } else if (step == 1) { |