[PATCH] rpc: Don't leak fd via CreateXMLWithFiles

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ben Gray <ben.r.gray@xxxxxxxxx>

FD passing APIs like CreateXMLWithFiles or OpenGraphicsFD will leak
file descriptors. The user passes in an fd, which is dup()'d in
virNetClientProgramCall. The new fd is what is transfered to the
server virNetClientIOWriteMessage.

Once all the fds have been written though, the parent msg->fds list
is immediately free'd, so the individual fds are never closed.

This closes each FD as its send to the server, so all fds have been
closed by the time msg->fds is free'd.

https://bugzilla.redhat.com/show_bug.cgi?id=1159766
Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
Ben's patch, my comments

 src/rpc/virnetclient.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 781e74c..d8ed15b 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -1177,20 +1177,21 @@ virNetClientIOWriteMessage(virNetClientPtr client,
 
     if (thecall->msg->bufferOffset == thecall->msg->bufferLength) {
         size_t i;
         for (i = thecall->msg->donefds; i < thecall->msg->nfds; i++) {
             int rv;
             if ((rv = virNetSocketSendFD(client->sock, thecall->msg->fds[i])) < 0)
                 return -1;
             if (rv == 0) /* Blocking */
                 return 0;
             thecall->msg->donefds++;
+            VIR_FORCE_CLOSE(thecall->msg->fds[i]);
         }
         thecall->msg->donefds = 0;
         thecall->msg->bufferOffset = thecall->msg->bufferLength = 0;
         VIR_FREE(thecall->msg->fds);
         VIR_FREE(thecall->msg->buffer);
         if (thecall->expectReply)
             thecall->mode = VIR_NET_CLIENT_MODE_WAIT_RX;
         else
             thecall->mode = VIR_NET_CLIENT_MODE_COMPLETE;
     }
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]