[Spice-devel] [PATCH spice-server v3 5/6] Avoid leaking file descriptor for statistics

Frediano Ziglio fziglio at redhat.com
Wed Nov 16 15:39:15 UTC 2016


mmap memory area will remain even if the descriptor is closed.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/stat-file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/server/stat-file.c b/server/stat-file.c
index e9b4208..5f54869 100644
--- a/server/stat-file.c
+++ b/server/stat-file.c
@@ -46,9 +46,11 @@ void stat_file_init(RedStatFile *stat_file, unsigned int max_nodes)
         spice_error("statistics shm_open failed, %s", strerror(errno));
     }
     if (ftruncate(fd, shm_size) == -1) {
+        close(fd);
         spice_error("statistics ftruncate failed, %s", strerror(errno));
     }
     stat_file->stat = (SpiceStat *)mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    close(fd);
     if (stat_file->stat == (SpiceStat *)MAP_FAILED) {
         spice_error("statistics mmap failed, %s", strerror(errno));
     }
-- 
2.7.4



More information about the Spice-devel mailing list