diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-22 12:39:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 12:39:11 (GMT) |
commit | 135ec7cefbaffd516b77362ad2b2ad1025af462e (patch) | |
tree | 1f92fbda32d21f0efc9f54432c32af03fe49a608 /Python/_warnings.c | |
parent | 3db0a21f731cec28a89f7495a82ee2670bce75fe (diff) | |
download | cpython-135ec7cefbaffd516b77362ad2b2ad1025af462e.zip cpython-135ec7cefbaffd516b77362ad2b2ad1025af462e.tar.gz cpython-135ec7cefbaffd516b77362ad2b2ad1025af462e.tar.bz2 |
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/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index d703e1e..046c37e 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -801,8 +801,7 @@ next_external_frame(PyFrameObject *frame) { do { PyFrameObject *back = PyFrame_GetBack(frame); - Py_DECREF(frame); - frame = back; + Py_SETREF(frame, back); } while (frame != NULL && is_internal_frame(frame)); return frame; @@ -828,8 +827,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, if (stack_level <= 0 || is_internal_frame(f)) { while (--stack_level > 0 && f != NULL) { PyFrameObject *back = PyFrame_GetBack(f); - Py_DECREF(f); - f = back; + Py_SETREF(f, back); } } else { |