summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2009-07-22 02:24:49 (GMT)
committerAlexandre Vassalotti <alexandre@peadrop.com>2009-07-22 02:24:49 (GMT)
commitfc477048e1dee78a1b4376584cac052be1b4752d (patch)
tree3018e0c1dc2d6896d3fd27d44f9ae63de3e27d61 /Modules/_io
parent4f1f422713358767de04642724ea4f96c6404f92 (diff)
downloadcpython-fc477048e1dee78a1b4376584cac052be1b4752d.zip
cpython-fc477048e1dee78a1b4376584cac052be1b4752d.tar.gz
cpython-fc477048e1dee78a1b4376584cac052be1b4752d.tar.bz2
Issue #6242: Fix deallocator of io.StringIO and io.BytesIO.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/bytesio.c8
-rw-r--r--Modules/_io/stringio.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 7675846..daef78f 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -609,11 +609,14 @@ bytesio_close(bytesio *self)
static void
bytesio_dealloc(bytesio *self)
{
+ _PyObject_GC_UNTRACK(self);
if (self->buf != NULL) {
PyMem_Free(self->buf);
self->buf = NULL;
}
- Py_TYPE(self)->tp_clear((PyObject *)self);
+ Py_CLEAR(self->dict);
+ if (self->weakreflist != NULL)
+ PyObject_ClearWeakRefs((PyObject *) self);
Py_TYPE(self)->tp_free(self);
}
@@ -667,7 +670,6 @@ static int
bytesio_traverse(bytesio *self, visitproc visit, void *arg)
{
Py_VISIT(self->dict);
- Py_VISIT(self->weakreflist);
return 0;
}
@@ -675,8 +677,6 @@ static int
bytesio_clear(bytesio *self)
{
Py_CLEAR(self->dict);
- if (self->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *)self);
return 0;
}
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
index 84a15be..d773723 100644
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -509,11 +509,15 @@ static void
stringio_dealloc(stringio *self)
{
_PyObject_GC_UNTRACK(self);
+ self->ok = 0;
+ if (self->buf) {
+ PyMem_Free(self->buf);
+ self->buf = NULL;
+ }
Py_CLEAR(self->readnl);
Py_CLEAR(self->writenl);
Py_CLEAR(self->decoder);
- if (self->buf)
- PyMem_Free(self->buf);
+ Py_CLEAR(self->dict);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
Py_TYPE(self)->tp_free(self);