mirror of
https://github.com/python/cpython.git
synced 2025-08-09 11:29:45 +00:00
gh-99537: Use Py_SETREF() function in C code (#99657)
Fix potential race condition in code patterns: * Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" * Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);" * Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);" Other changes: * Replace "old = var; var = new; Py_DECREF(var)" with "Py_SETREF(var, new);" * Replace "old = var; var = new; Py_XDECREF(var)" with "Py_XSETREF(var, new);" * And remove the "old" variable.
This commit is contained in:
parent
3db0a21f73
commit
135ec7cefb
19 changed files with 34 additions and 76 deletions
|
@ -5968,8 +5968,7 @@ object___dir___impl(PyObject *self)
|
|||
else {
|
||||
/* Copy __dict__ to avoid mutating it. */
|
||||
PyObject *temp = PyDict_Copy(dict);
|
||||
Py_DECREF(dict);
|
||||
dict = temp;
|
||||
Py_SETREF(dict, temp);
|
||||
}
|
||||
|
||||
if (dict == NULL)
|
||||
|
@ -9377,8 +9376,7 @@ super_getattro(PyObject *self, PyObject *name)
|
|||
(See SF ID #743627) */
|
||||
(su->obj == (PyObject *)starttype) ? NULL : su->obj,
|
||||
(PyObject *)starttype);
|
||||
Py_DECREF(res);
|
||||
res = res2;
|
||||
Py_SETREF(res, res2);
|
||||
}
|
||||
|
||||
Py_DECREF(mro);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue