]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-134885: zstd: Use Py_XSETREF (GH-134886)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Fri, 30 May 2025 09:30:05 +0000 (02:30 -0700)
committerGitHub <noreply@github.com>
Fri, 30 May 2025 09:30:05 +0000 (11:30 +0200)
Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst [new file with mode: 0644]
Modules/_zstd/_zstdmodule.c

diff --git a/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst b/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst
new file mode 100644 (file)
index 0000000..4b05d42
--- /dev/null
@@ -0,0 +1,2 @@
+Fix possible crash in the :mod:`compression.zstd` module related to setting
+parameter types. Patch by Jelle Zijlstra.
index 5ad697d2b83dd6395e4cf02d84471b434bb6ea01..986b3579479f0f357fb6c9d64f33b93139cb6a5d 100644 (file)
@@ -514,13 +514,10 @@ _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type,
         return NULL;
     }
 
-    Py_XDECREF(mod_state->CParameter_type);
-    Py_INCREF(c_parameter_type);
-    mod_state->CParameter_type = (PyTypeObject*)c_parameter_type;
-
-    Py_XDECREF(mod_state->DParameter_type);
-    Py_INCREF(d_parameter_type);
-    mod_state->DParameter_type = (PyTypeObject*)d_parameter_type;
+    Py_XSETREF(
+        mod_state->CParameter_type, (PyTypeObject*)Py_NewRef(c_parameter_type));
+    Py_XSETREF(
+        mod_state->DParameter_type, (PyTypeObject*)Py_NewRef(d_parameter_type));
 
     Py_RETURN_NONE;
 }