Browse Source

clear BufferedRWPair weakrefs on deallocation (closes #22517)

pull/2332/head
Benjamin Peterson 12 years ago
parent
commit
bbd0a323ae
  1. 6
      Lib/test/test_io.py
  2. 3
      Misc/NEWS
  3. 2
      Modules/_io/bufferedio.c

6
Lib/test/test_io.py

@ -1524,6 +1524,12 @@ class BufferedRWPairTest(unittest.TestCase):
pair = self.tp(SelectableIsAtty(True), SelectableIsAtty(True))
self.assertTrue(pair.isatty())
def test_weakref_clearing(self):
brw = self.tp(self.MockRawIO(), self.MockRawIO())
ref = weakref.ref(brw)
brw = None
ref = None # Shouldn't segfault.
class CBufferedRWPairTest(BufferedRWPairTest):
tp = io.BufferedRWPair

3
Misc/NEWS

@ -17,6 +17,9 @@ Core and Builtins
Library
-------
- Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
weakrefs.
- Issue #22419: Limit the length of incoming HTTP request in wsgiref server to
65536 bytes and send a 414 error code for higher lengths. Patch contributed
by Devin Cook.

2
Modules/_io/bufferedio.c

@ -2254,6 +2254,8 @@ static void
bufferedrwpair_dealloc(rwpair *self)
{
_PyObject_GC_UNTRACK(self);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)self);
Py_CLEAR(self->reader);
Py_CLEAR(self->writer);
Py_CLEAR(self->dict);

Loading…
Cancel
Save