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/_json.c | |
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/_json.c')
-rw-r--r-- | Modules/_json.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index 06f232f..81431aa 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -709,9 +709,7 @@ _parse_object_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ss if (memokey == NULL) { goto bail; } - Py_INCREF(memokey); - Py_DECREF(key); - key = memokey; + Py_SETREF(key, Py_NewRef(memokey)); idx = next_idx; /* skip whitespace between key and : delimiter, read :, skip whitespace */ |