summaryrefslogtreecommitdiff
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-22 13:39:11 +0100
committerGitHub <noreply@github.com>2022-11-22 13:39:11 +0100
commit135ec7cefbaffd516b77362ad2b2ad1025af462e (patch)
tree1f92fbda32d21f0efc9f54432c32af03fe49a608 /Objects/typeobject.c
parent3db0a21f731cec28a89f7495a82ee2670bce75fe (diff)
downloadcpython-git-135ec7cefbaffd516b77362ad2b2ad1025af462e.tar.gz
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.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 9d868d51f0..312406993c 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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);