Fix mounting on FreeBSD
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sun, 11 Nov 2018 10:46:14 +0000 (14:46 +0400)
committerNikolaus Rath <Nikolaus@rath.org>
Sun, 11 Nov 2018 19:40:25 +0000 (19:40 +0000)
Currently, mounting on FreeBSD fails like this:

 mount_fusefs: ZZZZ<snip> 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

index 94a11f73ad222dd977cb6a6d82561a961826773c..cbd3ced8755c58cfb0e186e015293a4bdbc99838 100644 (file)
@@ -222,6 +222,7 @@ mount:
                                if(ret == -1)
                                {
                                        perror("fuse: failed to assemble mount arguments");
+                                       close(fd);
                                        exit(1);
                                }
                        }
@@ -232,14 +233,11 @@ mount:
                                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);
                }