summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-11-03 13:37:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-11-03 13:37:01 (GMT)
commita7c972e03b03d3e5c5d1cea78ff73002aa7786b4 (patch)
tree2110c89c35bf92987ae74f95d70d77a88c517699 /Modules/_io
parent2af4144b7ff32e22d593fe16ce6f7762df94fbc5 (diff)
downloadcpython-a7c972e03b03d3e5c5d1cea78ff73002aa7786b4.zip
cpython-a7c972e03b03d3e5c5d1cea78ff73002aa7786b4.tar.gz
cpython-a7c972e03b03d3e5c5d1cea78ff73002aa7786b4.tar.bz2
Issue #28387: Fixed possible crash in _io.TextIOWrapper deallocator when
the garbage collector is invoked in other thread. Based on patch by Sebastian Cufre.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/textio.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 063caa6..5d7f9ab 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1103,7 +1103,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
}
static int
-_textiowrapper_clear(textio *self)
+textiowrapper_clear(textio *self)
{
self->ok = 0;
Py_CLEAR(self->buffer);
@@ -1116,6 +1116,8 @@ _textiowrapper_clear(textio *self)
Py_CLEAR(self->snapshot);
Py_CLEAR(self->errors);
Py_CLEAR(self->raw);
+
+ Py_CLEAR(self->dict);
return 0;
}
@@ -1125,11 +1127,11 @@ textiowrapper_dealloc(textio *self)
self->finalizing = 1;
if (_PyIOBase_finalize((PyObject *) self) < 0)
return;
- _textiowrapper_clear(self);
+ self->ok = 0;
_PyObject_GC_UNTRACK(self);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)self);
- Py_CLEAR(self->dict);
+ textiowrapper_clear(self);
Py_TYPE(self)->tp_free((PyObject *)self);
}
@@ -1151,15 +1153,6 @@ textiowrapper_traverse(textio *self, visitproc visit, void *arg)
return 0;
}
-static int
-textiowrapper_clear(textio *self)
-{
- if (_textiowrapper_clear(self) < 0)
- return -1;
- Py_CLEAR(self->dict);
- return 0;
-}
-
static PyObject *
textiowrapper_closed_get(textio *self, void *context);