summaryrefslogtreecommitdiffstats
path: root/Modules/audioop.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-22 13:22:22 (GMT)
committerGitHub <noreply@github.com>2022-11-22 13:22:22 (GMT)
commit7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e (patch)
treea8d4dda9e9128545442794595f5ebc96a5c1c7b4 /Modules/audioop.c
parent135ec7cefbaffd516b77362ad2b2ad1025af462e (diff)
downloadcpython-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/audioop.c')
-rw-r--r--Modules/audioop.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 6d484e8..9325f82 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1471,8 +1471,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
len = (Py_ssize_t)(ncp - PyBytes_AsString(str));
rv = PyBytes_FromStringAndSize
(PyBytes_AsString(str), len);
- Py_DECREF(str);
- str = rv;
+ Py_SETREF(str, rv);
if (str == NULL)
goto exit;
rv = Py_BuildValue("(O(iO))", str, d, samps);