Skip to content

Commit 9dfc211

Browse files
authored
Merge branch 'main' into fix-mock-open-read-data-doc
2 parents afc26a0 + 6679ac0 commit 9dfc211

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed a crash in :class:`subprocess.Popen` (and ``_posixsubprocess.fork_exec``)
2+
when an ``argv`` item's :meth:`~os.PathLike.__fspath__` concurrently mutates the
3+
``args`` sequence being converted.

Modules/_posixsubprocess.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,14 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
10901090
goto cleanup;
10911091
}
10921092
borrowed_arg = PySequence_Fast_GET_ITEM(fast_args, arg_num);
1093-
if (PyUnicode_FSConverter(borrowed_arg, &converted_arg) == 0)
1093+
/* borrowed_arg is only borrowed; its __fspath__() may run Python
1094+
that drops fast_args' last reference to it. */
1095+
Py_INCREF(borrowed_arg);
1096+
if (PyUnicode_FSConverter(borrowed_arg, &converted_arg) == 0) {
1097+
Py_DECREF(borrowed_arg);
10941098
goto cleanup;
1099+
}
1100+
Py_DECREF(borrowed_arg);
10951101
PyTuple_SET_ITEM(converted_args, arg_num, converted_arg);
10961102
}
10971103

0 commit comments

Comments
 (0)