summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2023-05-16 14:38:17 (GMT)
committerGitHub <noreply@github.com>2023-05-16 14:38:17 (GMT)
commit442a3e65da2594bedee88a3e81338d86926bde56 (patch)
tree47f03f721e2317a226379d0688b32c523928f73b
parent0bb61dd5b0ffc248e18f1b33cddd18788f28e60a (diff)
downloadcpython-442a3e65da2594bedee88a3e81338d86926bde56.zip
cpython-442a3e65da2594bedee88a3e81338d86926bde56.tar.gz
cpython-442a3e65da2594bedee88a3e81338d86926bde56.tar.bz2
GH-104510: Fix refleaks in `_io` base types (#104516)
-rw-r--r--Modules/_io/bufferedio.c11
-rw-r--r--Modules/_io/iobase.c11
-rw-r--r--Modules/_io/textio.c10
3 files changed, 6 insertions, 26 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 7a0c516..f30d54a 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -2424,13 +2424,6 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
#include "clinic/bufferedio.c.h"
#undef clinic_state
-static int
-bufferediobase_traverse(PyObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- return 0;
-}
-
static PyMethodDef bufferediobase_methods[] = {
_IO__BUFFEREDIOBASE_DETACH_METHODDEF
_IO__BUFFEREDIOBASE_READ_METHODDEF
@@ -2444,13 +2437,13 @@ static PyMethodDef bufferediobase_methods[] = {
static PyType_Slot bufferediobase_slots[] = {
{Py_tp_doc, (void *)bufferediobase_doc},
{Py_tp_methods, bufferediobase_methods},
- {Py_tp_traverse, bufferediobase_traverse},
{0, NULL},
};
+/* Do not set Py_TPFLAGS_HAVE_GC so that tp_traverse and tp_clear are inherited */
PyType_Spec bufferediobase_spec = {
.name = "_io._BufferedIOBase",
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = bufferediobase_slots,
};
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 14d4881..bcb498d 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -1036,13 +1036,6 @@ rawiobase_write(PyObject *self, PyObject *args)
return NULL;
}
-static int
-rawiobase_traverse(PyObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- return 0;
-}
-
static PyMethodDef rawiobase_methods[] = {
_IO__RAWIOBASE_READ_METHODDEF
_IO__RAWIOBASE_READALL_METHODDEF
@@ -1054,13 +1047,13 @@ static PyMethodDef rawiobase_methods[] = {
static PyType_Slot rawiobase_slots[] = {
{Py_tp_doc, (void *)rawiobase_doc},
{Py_tp_methods, rawiobase_methods},
- {Py_tp_traverse, rawiobase_traverse},
{0, NULL},
};
+/* Do not set Py_TPFLAGS_HAVE_GC so that tp_traverse and tp_clear are inherited */
PyType_Spec rawiobase_spec = {
.name = "_io._RawIOBase",
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = rawiobase_slots,
};
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index e858a1f..46411c7 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -167,12 +167,6 @@ textiobase_errors_get(PyObject *self, void *context)
Py_RETURN_NONE;
}
-static int
-textiobase_traverse(PyObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- return 0;
-}
static PyMethodDef textiobase_methods[] = {
_IO__TEXTIOBASE_DETACH_METHODDEF
@@ -193,13 +187,13 @@ static PyType_Slot textiobase_slots[] = {
{Py_tp_doc, (void *)textiobase_doc},
{Py_tp_methods, textiobase_methods},
{Py_tp_getset, textiobase_getset},
- {Py_tp_traverse, textiobase_traverse},
{0, NULL},
};
+/* Do not set Py_TPFLAGS_HAVE_GC so that tp_traverse and tp_clear are inherited */
PyType_Spec textiobase_spec = {
.name = "_io._TextIOBase",
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = textiobase_slots,
};