Close #12383: Fix subprocess module with env={}: don't copy the environment
variables, start with an empty environment.
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 4bcf159..06285e9 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1169,7 +1169,7 @@
                         # potential deadlocks, thus we do all this here.
                         # and pass it to fork_exec()
 
-                        if env:
+                        if env is not None:
                             env_list = [os.fsencode(k) + b'=' + os.fsencode(v)
                                         for k, v in env.items()]
                         else:
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index e6e8b3a..3ee2e6e 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -331,13 +331,22 @@
     def test_env(self):
         newenv = os.environ.copy()
         newenv["FRUIT"] = "orange"
-        p = subprocess.Popen([sys.executable, "-c",
-                              'import sys,os;'
-                              'sys.stdout.write(os.getenv("FRUIT"))'],
-                             stdout=subprocess.PIPE,
-                             env=newenv)
-        self.addCleanup(p.stdout.close)
-        self.assertEqual(p.stdout.read(), b"orange")
+        with subprocess.Popen([sys.executable, "-c",
+                               'import sys,os;'
+                               'sys.stdout.write(os.getenv("FRUIT"))'],
+                              stdout=subprocess.PIPE,
+                              env=newenv) as p:
+            stdout, stderr = p.communicate()
+            self.assertEqual(stdout, b"orange")
+
+    def test_empty_env(self):
+        with subprocess.Popen([sys.executable, "-c",
+                               'import os; '
+                               'print(len(os.environ))'],
+                              stdout=subprocess.PIPE,
+                              env={}) as p:
+            stdout, stderr = p.communicate()
+            self.assertEqual(stdout.strip(), b"0")
 
     def test_communicate_stdin(self):
         p = subprocess.Popen([sys.executable, "-c",