summaryrefslogtreecommitdiff
path: root/Modules/_struct.c
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-16 14:34:57 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-16 14:34:57 +0000
commitc602e21b6cd98a702558efd495cee279ae5b7385 (patch)
tree6c36a213c87581b2c1665399815825159e1c7c9d /Modules/_struct.c
parentd71841fe35e8332b59e4e7f92392dd343b8c5712 (diff)
downloadcpython-c602e21b6cd98a702558efd495cee279ae5b7385.tar.gz
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
Diffstat (limited to 'Modules/_struct.c')
-rw-r--r--Modules/_struct.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 6149964ecc..8e5420c7f7 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1471,7 +1471,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
return -1;
Py_INCREF(o_format);
- Py_XDECREF(soself->s_format);
+ Py_CLEAR(soself->s_format);
soself->s_format = o_format;
ret = prepare_s(soself);