]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #28387: Fixed possible crash in _io.TextIOWrapper deallocator when
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 3 Nov 2016 13:36:50 +0000 (15:36 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 3 Nov 2016 13:36:50 +0000 (15:36 +0200)
the garbage collector is invoked in other thread.
Based on patch by Sebastian Cufre.

Misc/ACKS
Misc/NEWS
Modules/_io/textio.c

index bec9a42ba16dff5d33e7063fcf1753832e97b28d..06de9e89b7d521ccea3acc30ca52ba72d99b445f 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -296,6 +296,7 @@ Simon Cross
 Felipe Cruz
 Drew Csillag
 Joaquin Cuenca Abela
+Sebastian Cufre
 John Cugini
 Tom Culliton
 Antonio Cuni
index a296d6a676372ffd3b552bc5b0f08b1abda11d43..34e45cd31f1c85bd8a017b0ac6a4a167b6b32594 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #28387: Fixed possible crash in _io.TextIOWrapper deallocator when
+  the garbage collector is invoked in other thread.  Based on patch by
+  Sebastian Cufre.
+
 - Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
   file with compression before trying to open it without compression.  Otherwise
   it had 50% chance failed with ignore_zeros=True.
index a95edced392e80b5ab631fd6839d818cf72fd6c4..b4007c27e7039d9ff3da5c194d50f20c328ff825 100644 (file)
@@ -1071,11 +1071,9 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
     return -1;
 }
 
-static int
+static void
 _textiowrapper_clear(textio *self)
 {
-    if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
-        return -1;
     self->ok = 0;
     Py_CLEAR(self->buffer);
     Py_CLEAR(self->encoding);
@@ -1087,18 +1085,19 @@ _textiowrapper_clear(textio *self)
     Py_CLEAR(self->snapshot);
     Py_CLEAR(self->errors);
     Py_CLEAR(self->raw);
-    return 0;
+
+    Py_CLEAR(self->dict);
 }
 
 static void
 textiowrapper_dealloc(textio *self)
 {
-    if (_textiowrapper_clear(self) < 0)
+    if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
         return;
     _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);
 }
 
@@ -1123,9 +1122,9 @@ textiowrapper_traverse(textio *self, visitproc visit, void *arg)
 static int
 textiowrapper_clear(textio *self)
 {
-    if (_textiowrapper_clear(self) < 0)
+    if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
         return -1;
-    Py_CLEAR(self->dict);
+    _textiowrapper_clear(self);
     return 0;
 }