diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
index b79f13d6ef25892ce22a426638f4b3c3a1f2753c_bWVyY3VyaWFsL3V0aWxzL3Byb2N1dGlsLnB5..a9e00554b3e482927113d0761e1eb7d382baaba6_bWVyY3VyaWFsL3V0aWxzL3Byb2N1dGlsLnB5 100644
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -686,4 +686,6 @@
         # we can't use close_fds *and* redirect stdin. I'm not sure that we
         # need to because the detached process has no console connection.
 
+        stdin = None
+
         try:
@@ -689,5 +691,4 @@
         try:
-            stdin = None
             if stdin_bytes is not None:
                 stdin = pycompat.unnamedtempfile()
                 stdin.write(stdin_bytes)