From 64e63d1ae717db4d3bdbe2346c3a8ed1725b8417 Mon Sep 17 00:00:00 2001
From: Gerardo Ganis <Gerardo.Ganis@cern.ch>
Date: Mon, 10 Apr 2017 15:21:31 +0200
Subject: [PATCH] proofd: fix for Coverity #67786

---
 proof/proofd/src/proofexecv.cxx | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/proof/proofd/src/proofexecv.cxx b/proof/proofd/src/proofexecv.cxx
index 9a31a37c678..db1ed9cf51d 100644
--- a/proof/proofd/src/proofexecv.cxx
+++ b/proof/proofd/src/proofexecv.cxx
@@ -639,9 +639,13 @@ int exportsock(rpdunix *conn)
    if (d == 0 || d == 1 || d == 2) {
       int fd = -1;
       int natt = 1000;
-      while (natt > 0 && (fd = dup(d)) <= 2) { natt--; }
+      while (natt > 0 && (fd = dup(d)) <= 2) {
+         if (fd != d) close(fd);
+         natt--;
+      }
       if (natt <= 0 && fd <= 2) {
          Info("exportsock: ERROR: no free filedescriptor!");
+         if (fd != d) close(fd);
          close(d);
          return -1;
       }
-- 
GitLab