https://github.com/python/cpython/commit/3bb0eb4ca97721de85ad394d0d010d9da2904da2
commit: 3bb0eb4ca97721de85ad394d0d010d9da2904da2
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-10-27T20:08:57Z
summary:

[3.14] gh-140634: Fix a reference counting bug in os.sched_param.__reduce__() 
(GH-140667) (GH-140685)

(cherry picked from commit 364ae607d8035db8ba92486ebebd8225446c1a90)

Co-authored-by: Serhiy Storchaka <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-10-27-13-49-31.gh-issue-140634.ULng9G.rst
M Lib/test/test_posix.py
M Modules/posixmodule.c

diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 0bb65fe717d359..aad6fc6b4b619b 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -1366,6 +1366,14 @@ def test_sched_param(self):
         self.assertNotEqual(newparam, param)
         self.assertEqual(newparam.sched_priority, 0)
 
+    @requires_sched
+    def test_bug_140634(self):
+        sched_priority = float('inf')  # any new reference
+        param = posix.sched_param(sched_priority)
+        param.__reduce__()
+        del sched_priority, param  # should not crash
+        support.gc_collect()  # just to be sure
+
     @unittest.skipUnless(hasattr(posix, "sched_rr_get_interval"), "no 
function")
     def test_sched_rr_get_interval(self):
         try:
diff --git 
a/Misc/NEWS.d/next/Library/2025-10-27-13-49-31.gh-issue-140634.ULng9G.rst 
b/Misc/NEWS.d/next/Library/2025-10-27-13-49-31.gh-issue-140634.ULng9G.rst
new file mode 100644
index 00000000000000..b1ba9b26ad5431
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-10-27-13-49-31.gh-issue-140634.ULng9G.rst
@@ -0,0 +1 @@
+Fix a reference counting bug in :meth:`!os.sched_param.__reduce__`.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 2dad3352982f7b..9295324f6c1eeb 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -8270,7 +8270,7 @@ os_sched_param_impl(PyTypeObject *type, PyObject 
*sched_priority)
 static PyObject *
 os_sched_param_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
 {
-    return Py_BuildValue("(O(N))", Py_TYPE(self), 
PyStructSequence_GetItem(self, 0));
+    return Py_BuildValue("(O(O))", Py_TYPE(self), 
PyStructSequence_GetItem(self, 0));
 }
 
 static PyMethodDef os_sched_param_reduce_method = {

_______________________________________________
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