[commit: packages/process] better-travis2, binary-handles, fix-appveyor, master: Close pipes on failure (a9a8e91)

git at git.haskell.org git at git.haskell.org
Wed Jul 19 21:16:41 UTC 2017


Repository : ssh://git@git.haskell.org/process

On branches: better-travis2,binary-handles,fix-appveyor,master
Link       : http://ghc.haskell.org/trac/ghc/changeset/a9a8e914e114913f5eea07da607b29c137bf2041/process

>---------------------------------------------------------------

commit a9a8e914e114913f5eea07da607b29c137bf2041
Author: Yuras Shumovich <shumovichy at gmail.com>
Date:   Thu May 26 13:46:21 2016 +0300

    Close pipes on failure
    
    Make sure stdin, stdout and stderr pipes are closed when exec call
    fails, e.g. when the executable doesn't exist.


>---------------------------------------------------------------

a9a8e914e114913f5eea07da607b29c137bf2041
 cbits/runProcess.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/cbits/runProcess.c b/cbits/runProcess.c
index 950635d..02dea87 100644
--- a/cbits/runProcess.c
+++ b/cbits/runProcess.c
@@ -84,6 +84,10 @@ runInteractiveProcess (char *const args[],
     if (fdStdOut == -1) {
         r = pipe(fdStdOutput);
         if (r == -1) {
+            if (fdStdIn == -1) {
+                close(fdStdInput[0]);
+                close(fdStdInput[1]);
+            }
             *failed_doing = "runInteractiveProcess: pipe";
             return -1;
         }
@@ -92,6 +96,14 @@ runInteractiveProcess (char *const args[],
         r = pipe(fdStdError);
         if (r == -1) {
             *failed_doing = "runInteractiveProcess: pipe";
+            if (fdStdIn == -1) {
+                close(fdStdInput[0]);
+                close(fdStdInput[1]);
+            }
+            if (fdStdOut == -1) {
+                close(fdStdOutput[0]);
+                close(fdStdOutput[1]);
+            }
             return -1;
         }
     }
@@ -328,6 +340,19 @@ runInteractiveProcess (char *const args[],
         // our responsibility to reap here as nobody else can.
         waitpid(pid, NULL, 0);
 
+        if (fdStdIn == -1) {
+            close(fdStdInput[0]);
+            close(fdStdInput[1]);
+        }
+        if (fdStdOut == -1) {
+            close(fdStdOutput[0]);
+            close(fdStdOutput[1]);
+        }
+        if (fdStdErr == -1) {
+            close(fdStdError[0]);
+            close(fdStdError[1]);
+        }
+
         pid = -1;
     }
     else if (r != 0) {



More information about the ghc-commits mailing list