summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-05-20 22:25:32 +0000
committerGuido van Rossum <guido@python.org>1998-05-20 22:25:32 +0000
commit0213efbeaccc8858882afd10f8d7168f3d97e875 (patch)
treedf5682c9b0d406ff116f5d736e42993d33c19e31 /Python
parent800e3ff6bbf6911b76efa2ab0c774bd708a55e00 (diff)
downloadcpython-0213efbeaccc8858882afd10f8d7168f3d97e875.tar.gz
Trivial little change: when setting a member to an object, hold the
old value in a temporary and XDECREF it only after then new value has been set. This prevents the (unlikely) case where the destructor of the member uses the containing object -- it would find it in an undefined state.
Diffstat (limited to 'Python')
-rw-r--r--Python/structmember.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Python/structmember.c b/Python/structmember.c
index 02464c611f..ba0772008a 100644
--- a/Python/structmember.c
+++ b/Python/structmember.c
@@ -167,6 +167,7 @@ PyMember_Set(addr, mlist, name, v)
PyObject *v;
{
struct memberlist *l;
+ PyObject *oldv;
for (l = mlist; l->name != NULL; l++) {
if (strcmp(l->name, name) == 0) {
@@ -253,9 +254,10 @@ PyMember_Set(addr, mlist, name, v)
}
break;
case T_OBJECT:
- Py_XDECREF(*(PyObject **)addr);
Py_XINCREF(v);
+ oldv = *(PyObject **)addr;
*(PyObject **)addr = v;
+ Py_XDECREF(oldv);
break;
case T_CHAR:
if (PyString_Check(v) &&