diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-22 13:22:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 13:22:22 (GMT) |
commit | 7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e (patch) | |
tree | a8d4dda9e9128545442794595f5ebc96a5c1c7b4 /Modules/_sqlite | |
parent | 135ec7cefbaffd516b77362ad2b2ad1025af462e (diff) | |
download | cpython-7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e.zip cpython-7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e.tar.gz cpython-7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e.tar.bz2 |
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.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/cursor.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 7844b6e..a4e22bb 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -1123,8 +1123,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self) PyObject *factory = self->row_factory; PyObject *args[] = { (PyObject *)self, row, }; PyObject *new_row = PyObject_Vectorcall(factory, args, 2, NULL); - Py_DECREF(row); - row = new_row; + Py_SETREF(row, new_row); } return row; } |