https://github.com/python/cpython/commit/446edda20919447fdc8b5a43f2f2ae686df82e6a
commit: 446edda20919447fdc8b5a43f2f2ae686df82e6a
branch: main
author: Michael Bommarito <[email protected]>
committer: emmatyping <[email protected]>
date: 2026-04-17T08:42:41-07:00
summary:

gh-148651: Fix refcount leak in _zstd decompressor options (#148657)

The option parsing in Modules/_zstd/decompressor.c had a missing 
Py_DECREF(value) before the early return -1 when PyLong_AsInt(key) fails. The 
identical code in Modules/_zstd/compressor.c line 158 has the fix.

files:
A Misc/NEWS.d/next/Library/2026-04-16-13-30-00.gh-issue-148651.ZsTdLk.rst
M Modules/_zstd/decompressor.c

diff --git 
a/Misc/NEWS.d/next/Library/2026-04-16-13-30-00.gh-issue-148651.ZsTdLk.rst 
b/Misc/NEWS.d/next/Library/2026-04-16-13-30-00.gh-issue-148651.ZsTdLk.rst
new file mode 100644
index 00000000000000..b69f94a17663dc
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-04-16-13-30-00.gh-issue-148651.ZsTdLk.rst
@@ -0,0 +1,2 @@
+Fix reference leak in :class:`compression.zstd.ZstdDecompressor` when an
+invalid option key is passed.
diff --git a/Modules/_zstd/decompressor.c b/Modules/_zstd/decompressor.c
index 0186ee92f5b147..46682b483ad06a 100644
--- a/Modules/_zstd/decompressor.c
+++ b/Modules/_zstd/decompressor.c
@@ -111,6 +111,7 @@ _zstd_set_d_parameters(ZstdDecompressor *self, PyObject 
*options)
         int key_v = PyLong_AsInt(key);
         Py_DECREF(key);
         if (key_v == -1 && PyErr_Occurred()) {
+            Py_DECREF(value);
             return -1;
         }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to