summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-22 12:39:11 (GMT)
committerGitHub <noreply@github.com>2022-11-22 12:39:11 (GMT)
commit135ec7cefbaffd516b77362ad2b2ad1025af462e (patch)
tree1f92fbda32d21f0efc9f54432c32af03fe49a608 /Python/errors.c
parent3db0a21f731cec28a89f7495a82ee2670bce75fe (diff)
downloadcpython-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/errors.c')
-rw-r--r--Python/errors.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/Python/errors.c b/Python/errors.c
index d74ac34..6a42f59 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -353,16 +353,13 @@ _PyErr_NormalizeException(PyThreadState *tstate, PyObject **exc,
if (fixed_value == NULL) {
goto error;
}
- Py_DECREF(value);
- value = fixed_value;
+ Py_SETREF(value, fixed_value);
}
/* If the class of the instance doesn't exactly match the
class of the type, believe the instance.
*/
else if (inclass != type) {
- Py_INCREF(inclass);
- Py_DECREF(type);
- type = inclass;
+ Py_SETREF(type, Py_NewRef(inclass));
}
}
*exc = type;