From: Simon Ruderich <simon@ruderich.org>
Date: Fri, 31 May 2013 16:37:55 +0000 (+0200)
Subject: fcntl(): Don't call dup_fd() if real_fcntl() failed.
X-Git-Tag: 0.1~135
X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=f369605227fb876e2edb0957a7c6ace98c49f7d3;p=coloredstderr%2Fcoloredstderr.git

fcntl(): Don't call dup_fd() if real_fcntl() failed.
---

diff --git a/src/coloredstderr.c b/src/coloredstderr.c
index dbcfd23..b2ef297 100644
--- a/src/coloredstderr.c
+++ b/src/coloredstderr.c
@@ -280,7 +280,7 @@ int fcntl(int fd, int cmd, int arg) {
 
     result = real_fcntl(fd, cmd, arg);
     /* We only care about duping fds. */
-    if (cmd == F_DUPFD) {
+    if (cmd == F_DUPFD && result != -1) {
         int saved_errno = errno;
         dup_fd(fd, result);
         errno = saved_errno;