gh-112075: Fix race in constructing dict for instance (#118499)

This commit is contained in:
Dino Viehland 2024-05-06 16:31:09 -07:00 committed by GitHub
parent 430945db4c
commit 636b8d94c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 216 additions and 71 deletions

View file

@ -1731,7 +1731,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
goto done;
}
else {
res = _PyObjectDict_SetItem(tp, dictptr, name, value);
res = _PyObjectDict_SetItem(tp, obj, dictptr, name, value);
}
}
else {
@ -1789,7 +1789,9 @@ PyObject_GenericSetDict(PyObject *obj, PyObject *value, void *context)
"not a '%.200s'", Py_TYPE(value)->tp_name);
return -1;
}
Py_BEGIN_CRITICAL_SECTION(obj);
Py_XSETREF(*dictptr, Py_NewRef(value));
Py_END_CRITICAL_SECTION();
return 0;
}