Skip to content

Commit 364ae60

Browse files
gh-140634: Fix a reference counting bug in os.sched_param.__reduce__() (GH-140667)
1 parent a716091 commit 364ae60

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Lib/test/test_os/test_posix.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,14 @@ def test_sched_param(self):
14271427
self.assertNotEqual(newparam, param)
14281428
self.assertEqual(newparam.sched_priority, 0)
14291429

1430+
@requires_sched
1431+
def test_bug_140634(self):
1432+
sched_priority = float('inf') # any new reference
1433+
param = posix.sched_param(sched_priority)
1434+
param.__reduce__()
1435+
del sched_priority, param # should not crash
1436+
support.gc_collect() # just to be sure
1437+
14301438
@unittest.skipUnless(hasattr(posix, "sched_rr_get_interval"), "no function")
14311439
def test_sched_rr_get_interval(self):
14321440
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
@@ -8724,7 +8724,7 @@ os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority)
87248724
static PyObject *
87258725
os_sched_param_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
87268726
{
8727-
return Py_BuildValue("(O(N))", Py_TYPE(self), PyStructSequence_GetItem(self, 0));
8727+
return Py_BuildValue("(O(O))", Py_TYPE(self), PyStructSequence_GetItem(self, 0));
87288728
}
87298729

87308730
static PyMethodDef os_sched_param_reduce_method = {

0 commit comments

Comments
 (0)