]> Git Repo - qemu.git/commitdiff
qemu-char: avoid leaking unused fds in tcp_get_msgfds()
authorStefan Hajnoczi <[email protected]>
Sun, 22 Jun 2014 02:38:37 +0000 (10:38 +0800)
committerMichael S. Tsirkin <[email protected]>
Mon, 23 Jun 2014 14:38:00 +0000 (17:38 +0300)
Commit c76bf6bb8fbbb233a7d3641e09229d23747d5ee3 ("Add chardev API
qemu_chr_fe_get_msgfds") extended the get_msgfds API from one to
multiple file descriptors.  It forgot to close unused file descriptors
before freeing the file descriptor array.

This patch prevents a file descriptor leak if the tcp_get_msgfds()
callers requests fewer file descriptors than are available.

Cc: Nikolay Nikolaev <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
qemu-char.c

index d9100a2201ec67fdec2c30b273715f7023eed6c7..e6cbafb09cafbf91b04bab369e9ed015d136bda4 100644 (file)
@@ -2481,8 +2481,15 @@ static int tcp_get_msgfds(CharDriverState *chr, int *fds, int num)
     int to_copy = (s->read_msgfds_num < num) ? s->read_msgfds_num : num;
 
     if (to_copy) {
+        int i;
+
         memcpy(fds, s->read_msgfds, to_copy * sizeof(int));
 
+        /* Close unused fds */
+        for (i = to_copy; i < s->read_msgfds_num; i++) {
+            close(s->read_msgfds[i]);
+        }
+
         g_free(s->read_msgfds);
         s->read_msgfds = 0;
         s->read_msgfds_num = 0;
This page took 0.029938 seconds and 4 git commands to generate.