bpo-30602: Fix refleak in os.spawnv() (#2212)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 15 Jun 2017 13:30:40 +0000 (15:30 +0200)
committerGitHub <noreply@github.com>
Thu, 15 Jun 2017 13:30:40 +0000 (15:30 +0200)
When os.spawnv() fails while handling arguments, free correctly
argvlist: pass lastarg+1 rather than lastarg to free_string_array()
to also free the first item.

Modules/posixmodule.c

index 470702981308e2e65265ecb4c9260c4132b68206..ff03b8dcdb02ad2d9fe5013f61c47cf06d68acb4 100644 (file)
@@ -5165,7 +5165,7 @@ os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv)
             return NULL;
         }
         if (i == 0 && !argvlist[0][0]) {
-            free_string_array(argvlist, i);
+            free_string_array(argvlist, i + 1);
             PyErr_SetString(
                 PyExc_ValueError,
                 "spawnv() arg 2 first element cannot be empty");