Skip to content

Commit 3bb0eb4

Browse files
[3.14] gh-140634: Fix a reference counting bug in os.sched_param.__reduce__() (GH-140667) (GH-140685)
(cherry picked from commit 364ae60) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent c1bfd4c commit 3bb0eb4

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Lib/test/test_posix.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,14 @@ def test_sched_param(self):
13661366
self.assertNotEqual(newparam, param)
13671367
self.assertEqual(newparam.sched_priority, 0)
13681368

1369+
@requires_sched
1370+
def test_bug_140634(self):
1371+
sched_priority = float('inf') # any new reference
1372+
param = posix.sched_param(sched_priority)
1373+
param.__reduce__()
1374+
del sched_priority, param # should not crash
1375+
support.gc_collect() # just to be sure
1376+
13691377
@unittest.skipUnless(hasattr(posix, "sched_rr_get_interval"), "no function")
13701378
def test_sched_rr_get_interval(self):
13711379
try:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a reference counting bug in :meth:`!os.sched_param.__reduce__`.

Modules/posixmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8270,7 +8270,7 @@ os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority)
82708270
static PyObject *
82718271
os_sched_param_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
82728272
{
8273-
return Py_BuildValue("(O(N))", Py_TYPE(self), PyStructSequence_GetItem(self, 0));
8273+
return Py_BuildValue("(O(O))", Py_TYPE(self), PyStructSequence_GetItem(self, 0));
82748274
}
82758275

82768276
static PyMethodDef os_sched_param_reduce_method = {

0 commit comments

Comments
 (0)