diff Modules/cStringIO.c @ 45373:f378edd21df2 legacy-trunk

Crashers of the day: Py_CLEAR must be used when there is a chance that the function can be called recursively. This was discussed in issue1020188. In python codebase, all occurrences of Py_[X]DECREF(xxx->yyy) are suspect, except when they appear in tp_new or tp_dealloc functions, or when the member cannot be of a user-defined class. Note that tp_init is not safe. I do have a (crashing) example for every changed line. Is it worth adding them to the test suite? Example: class SpecialStr(str): def __del__(self): s.close() import cStringIO s = cStringIO.StringIO(SpecialStr("text")) s.close() # Segfault
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Sat, 16 Feb 2008 14:34:57 +0000
parents 26384b8180c7
children 4fe192d48960
line wrap: on
line diff
--- a/Modules/cStringIO.c	Sat Feb 16 09:37:32 2008 +0000
+++ b/Modules/cStringIO.c	Sat Feb 16 14:34:57 2008 +0000
@@ -575,8 +575,7 @@
 
 static PyObject *
 I_close(Iobject *self, PyObject *unused) {
-        Py_XDECREF(self->pbuf);
-        self->pbuf = NULL;
+        Py_CLEAR(self->pbuf);
         self->buf = NULL;
 
         self->pos = self->string_size = 0;