virtiofsd: leak fixes
v2 cover virtiofsd: leak fixes
Patch 1-4 fixes memory/fd/hashmap leakage.
Patch 5 is a cleanup.
Liu Bo (5):
virtiofsd: cleanup allocated resource in se
virtiofsd: fix memory leak on lo.source
virtiofsd: fix memory leak on lo.inodes hashmap
virtiofsd: fix error handling in main()
virtiofsd: add helper for lo_data cleanup
contrib/virtiofsd/fuse_lowlevel.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.h | 2 +- contrib/virtiofsd/passthrough_ll.c | 36 ++++++++++++++++++++++-------------- 4 files changed, 37 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/5 virtiofsd: cleanup allocated resource in se
This cleans up unfreed resources in se on quiting, including se->virtio_dev, se->vu_socket_path, se->vu_socketfd.
--- contrib/virtiofsd/fuse_lowlevel.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.h | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-)
contrib/virtiofsd/fuse_lowlevel.c +7 -0
@@ -2557,6 +2557,13 @@ void fuse_session_destroy(struct fuse_session *se)free (se->cuse_data);if (se->fd !=-1 )close (se->fd); + +if (se->vu_socket_path) { +virtio_session_close (se); +free (se->vu_socket_path); + se->vu_socket_path =NULL ; + } +free (se); }
contrib/virtiofsd/fuse_virtio.c +7 -0
@@ -886,6 +886,13 @@ int virtio_session_mount(struct fuse_session *se)return 0 ; } +void virtio_session_close (struct fuse_session *se) +{ +close (se->vu_socketfd); +free (se->virtio_dev); + se->virtio_dev =NULL ; +} +int64_t fuse_virtio_map (fuse_req_t req,VhostUserFSSlaveMsg *msg,int fd) {if (!req->se->virtio_dev)return -ENODEV ;
contrib/virtiofsd/fuse_virtio.h +1 -1
@@ -19,7 +19,7 @@struct fuse_session ;int virtio_session_mount (struct fuse_session *se); - +void virtio_session_close (struct fuse_session *se);int virtio_loop (struct fuse_session *se);
Signature · 1 line
1.8.3.1
Re: [Virtio-fs] [PATCH v2 1/5] virtiofsd: cleanup allocated resource in se
Quoted 4 lines · * Liu Bo ([email protected]) wrote:
This cleans up unfreed resources in se on quiting, including
se->virtio_dev,se->vu_socket_path,se->vu_socketfd.Signed-off-by Liu Bo <[email protected]>
Quoted 58 lines
--- contrib/virtiofsd/fuse_lowlevel.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.h | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-)contrib/virtiofsd/fuse_lowlevel.c +7
-0@@ -2557,6 +2557,13 @@ void fuse_session_destroy(struct fuse_session *se)free (se->cuse_data);if (se->fd !=-1 )close (se->fd); + +if (se->vu_socket_path) { +virtio_session_close (se); +free (se->vu_socket_path); + se->vu_socket_path =NULL ; + } +free (se); }contrib/virtiofsd/fuse_virtio.c +7
-0@@ -886,6 +886,13 @@ int virtio_session_mount(struct fuse_session *se)return 0 ; } +void virtio_session_close (struct fuse_session *se) +{ +close (se->vu_socketfd); +free (se->virtio_dev); + se->virtio_dev =NULL ; +} +int64_t fuse_virtio_map (fuse_req_t req,VhostUserFSSlaveMsg *msg,int fd) {if (!req->se->virtio_dev)return -ENODEV ;contrib/virtiofsd/fuse_virtio.h +1
-1@@ -19,7 +19,7 @@struct fuse_session ;int virtio_session_mount (struct fuse_session *se); - +void virtio_session_close (struct fuse_session *se);int virtio_loop (struct fuse_session *se);Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH v2 2/5 virtiofsd: fix memory leak on lo.source
In reply to Liu Bovalgrind reported that lo.source is leaked on quiting, but it was defined as (const char*) as it may point to a const string "/".
--- contrib/virtiofsd/passthrough_ll.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
contrib/virtiofsd/passthrough_ll.c +3 -2
@@ -2269,9 +2269,8 @@ int main(int argc, char *argv[])err (1 ,"failed to stat source (\"%s\")" , lo.source);if (!S_ISDIR (stat.st_mode))errx (1 ,"source is not a directory" ); - }else { - lo.source ="/" ; + lo.source =strdup ("/" ); } lo.root.is_symlink = false;if (!lo.timeout_set) {
@@ -2333,5 +2332,7 @@ err_out1:if (lo.root.fd >=0 )close (lo.root.fd); +free ((char *)lo.source); +return ret ?1 :0 ; }
Signature · 1 line
1.8.3.1
Re: [Virtio-fs] [PATCH v2 2/5] virtiofsd: fix memory leak on lo.source
Quoted 4 lines · * Liu Bo ([email protected]) wrote:
valgrind reported that lo.source is leaked on quiting, but it was defined as (const char*) as it may point to a const string "/".
Signed-off-by Liu Bo <[email protected]>
Quoted 30 lines
--- contrib/virtiofsd/passthrough_ll.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)contrib/virtiofsd/passthrough_ll.c +3
-2@@ -2269,9 +2269,8 @@ int main(int argc, char *argv[])err (1 ,"failed to stat source (\"%s\")" , lo.source);if (!S_ISDIR (stat.st_mode))errx (1 ,"source is not a directory" ); - }else { - lo.source ="/" ; + lo.source =strdup ("/" ); } lo.root.is_symlink = false;if (!lo.timeout_set) {@@ -2333,5 +2332,7 @@ err_out1:if (lo.root.fd >=0 )close (lo.root.fd); +free ((char *)lo.source); +return ret ?1 :0 ; }Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH v2 3/5 virtiofsd: fix memory leak on lo.inodes hashmap
In reply to Liu Bolo.inodes hashmap was not unref/destroy 'd on quiting, which was caught by valgrind.
--- contrib/virtiofsd/passthrough_ll.c | 2 ++ 1 file changed, 2 insertions(+)
contrib/virtiofsd/passthrough_ll.c +2 -0
@@ -2321,6 +2321,8 @@ err_out2: err_out1:fuse_opt_free_args (&args); +if (lo.inodes) +g_hash_table_destroy (lo.inodes);lo_map_destroy (&lo.fd_map);lo_map_destroy (&lo.dirp_map);lo_map_destroy (&lo.ino_map);
Signature · 1 line
1.8.3.1
PATCH v2 4/5 virtiofsd: fix error handling in main()
In reply to Liu BoNeither fuse_parse_cmdline() nor fuse_opt_parse() goes to the right place to do cleanup.
--- contrib/virtiofsd/passthrough_ll.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
contrib/virtiofsd/passthrough_ll.c +3 -2
@@ -2242,7 +2242,8 @@ int main(int argc, char *argv[])lo_map_init (&lo.fd_map);if (fuse_parse_cmdline (&args, &opts) !=0 ) -return 1 ; + goto err_out1; +if (opts.show_help) {printf ("usage: %s [options]\n\n" , argv[0 ]);fuse_cmdline_help ();
@@ -2257,7 +2258,7 @@ int main(int argc, char *argv[]) }if (fuse_opt_parse (&args, &lo, lo_opts,NULL )==-1 ) -return 1 ; + goto err_out1; lo.debug = opts.debug;if (lo.source) {
Signature · 1 line
1.8.3.1
PATCH v2 5/5 virtiofsd: add helper for lo_data cleanup
In reply to Liu BoThis offers an helper function for lo_data's cleanup.
--- contrib/virtiofsd/passthrough_ll.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
contrib/virtiofsd/passthrough_ll.c +18 -14
@@ -2205,6 +2205,23 @@ static gboolean lo_key_equal(gconstpointer a, gconstpointer b) la->dev == lb->dev; } +static void fuse_lo_data_cleanup (struct lo_data *lo) +{ +if (lo->inodes) +g_hash_table_destroy (lo->inodes); +lo_map_destroy (&lo->fd_map); +lo_map_destroy (&lo->dirp_map); +lo_map_destroy (&lo->ino_map); + +if (lo->proc_self_fd >=0 ) { +close (lo->proc_self_fd); + } + +if (lo->root.fd >=0 ) +close (lo->root.fd); + +free ((char *)lo->source); +}int main (int argc,char *argv[]) {
@@ -2322,20 +2339,7 @@ err_out2: err_out1:fuse_opt_free_args (&args); -if (lo.inodes) -g_hash_table_destroy (lo.inodes); -lo_map_destroy (&lo.fd_map); -lo_map_destroy (&lo.dirp_map); -lo_map_destroy (&lo.ino_map); - -if (lo.proc_self_fd >=0 ) { -close (lo.proc_self_fd); - } - -if (lo.root.fd >=0 ) -close (lo.root.fd); - -free ((char *)lo.source); +fuse_lo_data_cleanup (&lo);return ret ?1 :0 ; }
Signature · 1 line
1.8.3.1
Quoted 2 lines · * Liu Bo ([email protected]) wrote:
Patch 1-4 fixes memory/fd/hashmap leakage.
Patch 5 is a cleanup.
I've just pushed a new -dev branch that includes this and a bunch of other fixes.
Dave
Quoted 7 lines
Liu Bo (5):
virtiofsd: cleanup allocated resource in se
virtiofsd: fix memory leak on lo.source
virtiofsd: fix memory leak on lo.inodes hashmap
virtiofsd: fix error handling inmain()
virtiofsd: add helper forlo_datacleanup
Quoted 9 lines
contrib/virtiofsd/fuse_lowlevel.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.c | 7 +++++++ contrib/virtiofsd/fuse_virtio.h | 2 +- contrib/virtiofsd/passthrough_ll.c | 36 ++++++++++++++++++++++-------------- 4 files changed, 37 insertions(+), 15 deletions(-)Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK