[libvirt] [PATCH 2/3] virnetsocket: Resolve Coverity RESOURCE_LEAK

John Ferlan jferlan at redhat.com
Fri Aug 22 15:28:20 UTC 2014


Since '1b807f92d' - Coverity complains that in the error paths of
both virFork() and virProcessWait() that the 'passfd' will not be closed

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/rpc/virnetsocket.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index f913365..ce908fa 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -593,8 +593,10 @@ int virNetSocketNewConnectUNIX(const char *path,
          * behaviour on sockets according to POSIX, so it doesn't
          * work outside Linux.
          */
-        if ((pid = virFork()) < 0)
+        if ((pid = virFork()) < 0) {
+            VIR_FORCE_CLOSE(passfd);
             goto error;
+        }
 
         if (pid == 0) {
             umask(0077);
@@ -604,8 +606,10 @@ int virNetSocketNewConnectUNIX(const char *path,
             _exit(EXIT_SUCCESS);
         }
 
-        if (virProcessWait(pid, &status, false) < 0)
+        if (virProcessWait(pid, &status, false) < 0) {
+            VIR_FORCE_CLOSE(passfd);
             goto error;
+        }
 
         if (status != EXIT_SUCCESS) {
             /*
-- 
1.9.3




More information about the libvir-list mailing list