Blame 0087-virtiofsd-cleanup-allocated-resource-in-se.patch

1d442b
From: Liu Bo <bo.liu@linux.alibaba.com>
1d442b
Date: Mon, 27 Jan 2020 19:01:56 +0000
1d442b
Subject: [PATCH] virtiofsd: cleanup allocated resource in se
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
This cleans up unfreed resources in se on quiting, including
1d442b
se->virtio_dev, se->vu_socket_path, se->vu_socketfd.
1d442b
1d442b
Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
1d442b
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit 61cfc44982e566c33b9d5df17858e4d5ae373873)
1d442b
---
1d442b
 tools/virtiofsd/fuse_lowlevel.c | 7 +++++++
1d442b
 tools/virtiofsd/fuse_virtio.c   | 7 +++++++
1d442b
 tools/virtiofsd/fuse_virtio.h   | 2 +-
1d442b
 3 files changed, 15 insertions(+), 1 deletion(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
1d442b
index 65f91dabae..440508a6ec 100644
1d442b
--- a/tools/virtiofsd/fuse_lowlevel.c
1d442b
+++ b/tools/virtiofsd/fuse_lowlevel.c
1d442b
@@ -2532,6 +2532,13 @@ void fuse_session_destroy(struct fuse_session *se)
1d442b
     if (se->fd != -1) {
1d442b
         close(se->fd);
1d442b
     }
1d442b
+
1d442b
+    if (se->vu_socket_path) {
1d442b
+        virtio_session_close(se);
1d442b
+        free(se->vu_socket_path);
1d442b
+        se->vu_socket_path = NULL;
1d442b
+    }
1d442b
+
1d442b
     free(se);
1d442b
 }
1d442b
 
1d442b
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
1d442b
index 7a8774a3ee..e7bd772805 100644
1d442b
--- a/tools/virtiofsd/fuse_virtio.c
1d442b
+++ b/tools/virtiofsd/fuse_virtio.c
1d442b
@@ -833,3 +833,10 @@ int virtio_session_mount(struct fuse_session *se)
1d442b
 
1d442b
     return 0;
1d442b
 }
1d442b
+
1d442b
+void virtio_session_close(struct fuse_session *se)
1d442b
+{
1d442b
+    close(se->vu_socketfd);
1d442b
+    free(se->virtio_dev);
1d442b
+    se->virtio_dev = NULL;
1d442b
+}
1d442b
diff --git a/tools/virtiofsd/fuse_virtio.h b/tools/virtiofsd/fuse_virtio.h
1d442b
index cc676b9193..111684032c 100644
1d442b
--- a/tools/virtiofsd/fuse_virtio.h
1d442b
+++ b/tools/virtiofsd/fuse_virtio.h
1d442b
@@ -19,7 +19,7 @@
1d442b
 struct fuse_session;
1d442b
 
1d442b
 int virtio_session_mount(struct fuse_session *se);
1d442b
-
1d442b
+void virtio_session_close(struct fuse_session *se);
1d442b
 int virtio_loop(struct fuse_session *se);
1d442b
 
1d442b