Skip to content

Commit 45c6c48

Browse files
gh-134885: zstd: Use Py_XSETREF (GH-134886)
1 parent b367e27 commit 45c6c48

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible crash in the :mod:`compression.zstd` module related to setting
2+
parameter types. Patch by Jelle Zijlstra.

Modules/_zstd/_zstdmodule.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,10 @@ _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type,
514514
return NULL;
515515
}
516516

517-
Py_XDECREF(mod_state->CParameter_type);
518-
Py_INCREF(c_parameter_type);
519-
mod_state->CParameter_type = (PyTypeObject*)c_parameter_type;
520-
521-
Py_XDECREF(mod_state->DParameter_type);
522-
Py_INCREF(d_parameter_type);
523-
mod_state->DParameter_type = (PyTypeObject*)d_parameter_type;
517+
Py_XSETREF(
518+
mod_state->CParameter_type, (PyTypeObject*)Py_NewRef(c_parameter_type));
519+
Py_XSETREF(
520+
mod_state->DParameter_type, (PyTypeObject*)Py_NewRef(d_parameter_type));
524521

525522
Py_RETURN_NONE;
526523
}

0 commit comments

Comments
 (0)