From f28f9304bf6d79c7ce2274e9f929fabde26d7afb Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 30 May 2025 12:50:42 +0200 Subject: [3.14] gh-134885: zstd: Use Py_XSETREF (GH-134886) (GH-134922) (cherry picked from commit 45c6c48afc13f9897010e32171a3e02d0624258c) Co-authored-by: Jelle Zijlstra --- .../Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst | 2 ++ Modules/_zstd/_zstdmodule.c | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst 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 index 0000000..4b05d42 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst @@ -0,0 +1,2 @@ +Fix possible crash in the :mod:`compression.zstd` module related to setting +parameter types. Patch by Jelle Zijlstra. diff --git a/Modules/_zstd/_zstdmodule.c b/Modules/_zstd/_zstdmodule.c index 5ad697d..986b357 100644 --- a/Modules/_zstd/_zstdmodule.c +++ b/Modules/_zstd/_zstdmodule.c @@ -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; } -- cgit v0.12