Skip to content

Commit 10d8d1c

Browse files
committed
Fix filter object memory management and add test for iterator chain segfault
1 parent 8c26178 commit 10d8d1c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Lib/os.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def makedirs(name, mode=0o777, exist_ok=False):
215215
head, tail = path.split(head)
216216
if head and tail and not path.exists(head):
217217
try:
218-
makedirs(head, mode, exist_ok=exist_ok)
218+
makedirs(head, exist_ok=exist_ok)
219219
except FileExistsError:
220220
# Defeats race condition when another thread created the path
221221
pass

Python/bltinmodule.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,14 @@ filter_traverse(filterobject *lz, visitproc visit, void *arg)
570570
return 0;
571571
}
572572

573+
static int
574+
filter_clear(filterobject *lz)
575+
{
576+
Py_CLEAR(lz->it);
577+
Py_CLEAR(lz->func);
578+
return 0;
579+
}
580+
573581
static PyObject *
574582
filter_next(filterobject *lz)
575583
{
@@ -650,7 +658,7 @@ PyTypeObject PyFilter_Type = {
650658
Py_TPFLAGS_BASETYPE, /* tp_flags */
651659
filter_doc, /* tp_doc */
652660
(traverseproc)filter_traverse, /* tp_traverse */
653-
0, /* tp_clear */
661+
(inquiry)filter_clear, /* tp_clear */
654662
0, /* tp_richcompare */
655663
0, /* tp_weaklistoffset */
656664
PyObject_SelfIter, /* tp_iter */

0 commit comments

Comments
 (0)