Skip to content

Commit

Permalink
pythongh-104372: Use non-Raw malloc for c_fds_to_keep in _posixsubpro…
Browse files Browse the repository at this point in the history
…cess (python#104697)

Use non-Raw malloc for c_fds_to_keep as the code could ask for 0 length.
  • Loading branch information
gpshead authored May 20, 2023
1 parent 68ee8b3 commit d1732fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
#endif /* HAVE_SETREUID */
}

c_fds_to_keep = PyMem_RawMalloc(fds_to_keep_len * sizeof(int));
c_fds_to_keep = PyMem_Malloc(fds_to_keep_len * sizeof(int));
if (c_fds_to_keep == NULL) {
PyErr_SetString(PyExc_MemoryError, "failed to malloc c_fds_to_keep");
goto cleanup;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,

cleanup:
if (c_fds_to_keep != NULL) {
PyMem_RawFree(c_fds_to_keep);
PyMem_Free(c_fds_to_keep);
}

if (saved_errno != 0) {
Expand Down

0 comments on commit d1732fe

Please sign in to comment.