diff options
| author | Victor Stinner <vstinner@python.org> | 2022-11-22 13:39:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-22 13:39:11 +0100 |
| commit | 135ec7cefbaffd516b77362ad2b2ad1025af462e (patch) | |
| tree | 1f92fbda32d21f0efc9f54432c32af03fe49a608 /Objects/setobject.c | |
| parent | 3db0a21f731cec28a89f7495a82ee2670bce75fe (diff) | |
| download | cpython-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/setobject.c')
| -rw-r--r-- | Objects/setobject.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index e064676838..ae9e9b9944 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1270,8 +1270,7 @@ set_intersection_multi(PySetObject *so, PyObject *args) Py_DECREF(result); return NULL; } - Py_DECREF(result); - result = newresult; + Py_SETREF(result, newresult); } return result; } |
