From 11d9ed614f9000cff349f077983e83b7901e7ed2 Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Sun, 11 Nov 2018 14:46:14 +0400 Subject: [PATCH] Fix mounting on FreeBSD Currently, mounting on FreeBSD fails like this: mount_fusefs: ZZZZ on /mountpoint: No such file or directory This happens because right after doing argv[a++] = fdnam it's getting freed before calling execvp(). So move this free() call after execvp(). Also, when asprintf() fails for fdnam, close device fd before calling exit(). --- lib/mount_bsd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/mount_bsd.c b/lib/mount_bsd.c index 94a11f73a..cbd3ced87 100644 --- a/lib/mount_bsd.c +++ b/lib/mount_bsd.c @@ -222,6 +222,7 @@ static int fuse_mount_core(const char *mountpoint, const char *opts) if(ret == -1) { perror("fuse: failed to assemble mount arguments"); + close(fd); exit(1); } } @@ -232,14 +233,11 @@ static int fuse_mount_core(const char *mountpoint, const char *opts) argv[a++] = opts; } argv[a++] = fdnam; - - if(ret != -1) - free(fdnam); - argv[a++] = mountpoint; argv[a++] = NULL; execvp(mountprog, (char **) argv); perror("fuse: failed to exec mount program"); + free(fdnam); exit(1); }