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 /Python/pythonrun.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 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 70872222eb..35292b6478 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -718,8 +718,7 @@ _Py_HandleSystemExit(int *exitcode_p) /* The error code should be in the `code' attribute. */ PyObject *code = PyObject_GetAttr(value, &_Py_ID(code)); if (code) { - Py_DECREF(value); - value = code; + Py_SETREF(value, code); if (value == Py_None) goto done; } |