gh-99537: Use Py_SETREF() function in C code (#99656)
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:
@@ -1105,8 +1105,7 @@ fromBignumObj(TkappObject *tkapp, Tcl_Obj *value)
|
||||
PyMem_Free(bytes);
|
||||
if (res != NULL && bigValue.sign == MP_NEG) {
|
||||
PyObject *res2 = PyNumber_Negative(res);
|
||||
Py_DECREF(res);
|
||||
res = res2;
|
||||
Py_SETREF(res, res2);
|
||||
}
|
||||
mp_clear(&bigValue);
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user