Skip to content

Commit adf0e43

Browse files
committed
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.
1 parent 885215c commit adf0e43

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Python/structmember.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ PyMember_Set(addr, mlist, name, v)
167167
PyObject *v;
168168
{
169169
struct memberlist *l;
170+
PyObject *oldv;
170171

171172
for (l = mlist; l->name != NULL; l++) {
172173
if (strcmp(l->name, name) == 0) {
@@ -253,9 +254,10 @@ PyMember_Set(addr, mlist, name, v)
253254
}
254255
break;
255256
case T_OBJECT:
256-
Py_XDECREF(*(PyObject **)addr);
257257
Py_XINCREF(v);
258+
oldv = *(PyObject **)addr;
258259
*(PyObject **)addr = v;
260+
Py_XDECREF(oldv);
259261
break;
260262
case T_CHAR:
261263
if (PyString_Check(v) &&

0 commit comments

Comments
 (0)