mirror of
https://github.com/python/cpython.git
synced 2026-05-06 20:51:17 -04:00
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.
This commit is contained in:
+1
-2
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user