Skip to content

Commit 526b226

Browse files
authored
bpo-30602: Fix refleak in os.spawnve() (#2184)
When os.spawnve() fails while handling arguments, free correctly argvlist: pass lastarg+1 rather than lastarg to free_string_array() to also free the first item.
1 parent 3402f72 commit 526b226

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Modules/posixmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5223,7 +5223,7 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
52235223
Py_ssize_t argc, i, envc;
52245224
intptr_t spawnval;
52255225
PyObject *(*getitem)(PyObject *, Py_ssize_t);
5226-
Py_ssize_t lastarg = 0;
5226+
Py_ssize_t lastarg = -1;
52275227

52285228
/* spawnve has four arguments: (mode, path, argv, env), where
52295229
argv is a list or tuple of strings and env is a dictionary
@@ -5302,7 +5302,7 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
53025302
PyMem_DEL(envlist[envc]);
53035303
PyMem_DEL(envlist);
53045304
fail_1:
5305-
free_string_array(argvlist, lastarg);
5305+
free_string_array(argvlist, lastarg + 1);
53065306
fail_0:
53075307
return res;
53085308
}

0 commit comments

Comments
 (0)