[2.7] bpo-31471: Fix assertion failure in subprocess.Popen() on Windows, in case env has a bad keys() method. (GH-3580) (#3595)
diff --git a/PC/_subprocess.c b/PC/_subprocess.c
index f73d14f..fc9aaa4 100644
--- a/PC/_subprocess.c
+++ b/PC/_subprocess.c
@@ -341,9 +341,13 @@
envsize = PyMapping_Length(environment);
keys = PyMapping_Keys(environment);
+ if (!keys) {
+ return NULL;
+ }
values = PyMapping_Values(environment);
- if (!keys || !values)
+ if (!values) {
goto error;
+ }
out = PyString_FromStringAndSize(NULL, 2048);
if (! out)