Close pipes on failure
authorYuras Shumovich <shumovichy@gmail.com>
Tue, 3 Apr 2018 17:58:49 +0000 (20:58 +0300)
committerYuras Shumovich <shumovichy@gmail.com>
Wed, 4 Apr 2018 12:14:18 +0000 (15:14 +0300)
When we fail to create communication pipe, we should cleanup resources
before exit. E.g. we should close pipes for stdin, stdout and stderr if
they where created. Fixes #122.

cbits/runProcess.c
changelog.md

index ae184c8..16ef4fe 100644 (file)
@@ -111,6 +111,18 @@ runInteractiveProcess (char *const args[],
     r = pipe(forkCommunicationFds);
     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]);
+        }
+        if (fdStdErr == -1) {
+            close(fdStdError[0]);
+            close(fdStdError[1]);
+        }
         return -1;
     }
 
index bf22183..ba7bab5 100644 (file)
@@ -2,6 +2,9 @@
 
 ## Unreleased changes
 
+* Bug fix: Don't leak pipes on failure
+  [#122](https://github.com/haskell/process/issues/122)
+
 ## 1.6.3.0 *January 2018*
 
 * Added `getPid` and export of platform specific `Pid` type