mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-111049: Fix crash during garbage collection of the BytesIO buffer object (GH-111221)
This commit is contained in:
parent
4d5d9acb22
commit
bb36f72efc
3 changed files with 27 additions and 10 deletions
|
|
@ -990,7 +990,9 @@ static int
|
|||
bytesio_clear(bytesio *self)
|
||||
{
|
||||
Py_CLEAR(self->dict);
|
||||
Py_CLEAR(self->buf);
|
||||
if (self->exports == 0) {
|
||||
Py_CLEAR(self->buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1095,13 +1097,6 @@ bytesiobuf_releasebuffer(bytesiobuf *obj, Py_buffer *view)
|
|||
b->exports--;
|
||||
}
|
||||
|
||||
static int
|
||||
bytesiobuf_clear(bytesiobuf *self)
|
||||
{
|
||||
Py_CLEAR(self->source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
bytesiobuf_traverse(bytesiobuf *self, visitproc visit, void *arg)
|
||||
{
|
||||
|
|
@ -1116,7 +1111,7 @@ bytesiobuf_dealloc(bytesiobuf *self)
|
|||
PyTypeObject *tp = Py_TYPE(self);
|
||||
/* bpo-31095: UnTrack is needed before calling any callbacks */
|
||||
PyObject_GC_UnTrack(self);
|
||||
(void)bytesiobuf_clear(self);
|
||||
Py_CLEAR(self->source);
|
||||
tp->tp_free(self);
|
||||
Py_DECREF(tp);
|
||||
}
|
||||
|
|
@ -1124,7 +1119,6 @@ bytesiobuf_dealloc(bytesiobuf *self)
|
|||
static PyType_Slot bytesiobuf_slots[] = {
|
||||
{Py_tp_dealloc, bytesiobuf_dealloc},
|
||||
{Py_tp_traverse, bytesiobuf_traverse},
|
||||
{Py_tp_clear, bytesiobuf_clear},
|
||||
|
||||
// Buffer protocol
|
||||
{Py_bf_getbuffer, bytesiobuf_getbuffer},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue