]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-140634: Fix a reference counting bug in os.sched_param.__reduce__() (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 27 Oct 2025 20:05:10 +0000 (21:05 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Oct 2025 20:05:10 +0000 (20:05 +0000)
(cherry picked from commit 364ae607d8035db8ba92486ebebd8225446c1a90)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_posix.py
Misc/NEWS.d/next/Library/2025-10-27-13-49-31.gh-issue-140634.ULng9G.rst [new file with mode: 0644]
Modules/posixmodule.c

index c327d2add2f1cd1c075d6180fb18db8e2d04c3eb..ffda92ae53e9f6a2c44b8082d79c3080e94ef5c9 100644 (file)
@@ -1366,6 +1366,14 @@ class PosixTester(unittest.TestCase):
         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 (file)
index 0000000..b1ba9b2
--- /dev/null
@@ -0,0 +1 @@
+Fix a reference counting bug in :meth:`!os.sched_param.__reduce__`.
index 9c1564093b96bc82756919c0d47a4864eaf053cf..13c2c1fd6787f528c982ec98dfd75d9405fbb0b5 100644 (file)
@@ -8175,7 +8175,7 @@ os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority)
 static PyObject *
 os_sched_param_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
 {
-    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 = {