mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00: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:
parent
3db0a21f73
commit
135ec7cefb
19 changed files with 34 additions and 76 deletions
|
@ -473,8 +473,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
|||
goto error;
|
||||
|
||||
/* assign to obj */
|
||||
Py_DECREF(obj);
|
||||
obj = tmp;
|
||||
Py_SETREF(obj, tmp);
|
||||
}
|
||||
/* end of iterator, this is the non-error case */
|
||||
if (ok == 1)
|
||||
|
@ -825,8 +824,7 @@ output_markup(SubString *field_name, SubString *format_spec,
|
|||
goto done;
|
||||
|
||||
/* do the assignment, transferring ownership: fieldobj = tmp */
|
||||
Py_DECREF(fieldobj);
|
||||
fieldobj = tmp;
|
||||
Py_SETREF(fieldobj, tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue