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

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

index 46d6adf41340e394e50237e4ef12f7ca4ee0d4d4..fb3f2991aaf84962ebaef9161fc3a1834cc42c4b 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -315,6 +315,7 @@ Simon Cross
 Felipe Cruz
 Drew Csillag
 Joaquin Cuenca Abela
+Sebastian Cufre
 John Cugini
 Tom Culliton
 Raúl Cumplido
index af4eb312af22b3fb516f83826e7dd33da5d65d00..5410c77c6299ff565b3aa0cd9af1541c1ca17cd4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -113,6 +113,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 #27517: LZMA compressor and decompressor no longer raise exceptions if
   given empty data twice.  Patch by Benjamin Fogle.
 
index 063caa6067f6751c5a286223c5b3cdfeaa9bbdcd..5d7f9ab885c9c73890caa63fb6fbe1b70121b522 100644 (file)
@@ -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);