mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.11] gh-104698: Fix reference leak in mmapmodule.c (GH-104700) (#104710)
(cherry picked from commit 99b641886a
)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
2e457bc202
commit
b2e0201222
1 changed files with 19 additions and 3 deletions
|
@ -235,6 +235,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
|
||||
|
@ -245,6 +253,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 *
|
||||
|
@ -334,7 +350,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,
|
||||
|
@ -411,7 +427,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);
|
||||
|
@ -1097,7 +1113,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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue