Cuse example: Fix memory leak (#607)
authorChristian Menges <christian.menges@tum.de>
Wed, 9 Jun 2021 08:04:41 +0000 (10:04 +0200)
committerGitHub <noreply@github.com>
Wed, 9 Jun 2021 08:04:41 +0000 (09:04 +0100)
* cuse example: fix memory leak

* Travis CI: re-enable leak checking

example/cuse.c
test/travis-build.sh

index e2ccdcb5e913217546d53a5e3fc505d32c05712e..0c0e7bce75e98fd3f86b6b137d645bb1a84c9f40 100644 (file)
@@ -294,18 +294,21 @@ int main(int argc, char **argv)
        char dev_name[128] = "DEVNAME=";
        const char *dev_info_argv[] = { dev_name };
        struct cuse_info ci;
+       int ret = 1;
 
        if (fuse_opt_parse(&args, &param, cusexmp_opts, cusexmp_process_arg)) {
                printf("failed to parse option\n");
-               return 1;
+               free(param.dev_name);
+               goto out;
        }
 
        if (!param.is_help) {
                if (!param.dev_name) {
                        fprintf(stderr, "Error: device name missing\n");
-                       return 1;
+                       goto out;
                }
-               strncat(dev_name, param.dev_name, sizeof(dev_name) - 9);
+               strncat(dev_name, param.dev_name, sizeof(dev_name) - sizeof("DEVNAME="));
+               free(param.dev_name);
        }
 
        memset(&ci, 0, sizeof(ci));
@@ -315,6 +318,9 @@ int main(int argc, char **argv)
        ci.dev_info_argv = dev_info_argv;
        ci.flags = CUSE_UNRESTRICTED_IOCTL;
 
-       return cuse_lowlevel_main(args.argc, args.argv, &ci, &cusexmp_clop,
-                                 NULL);
+       ret = cuse_lowlevel_main(args.argc, args.argv, &ci, &cusexmp_clop, NULL);
+
+out:
+       fuse_opt_free_args(&args);
+       return ret;
 }
index 36859098c0fb55369c07301f7ce8efd6d35dc79d..04f3511b34a5930725eddcc07b84fe104f477a11 100755 (executable)
@@ -2,9 +2,7 @@
 
 set -e
 
-# Disable leak checking for now, there are some issues (or false positives)
-# that we still need to fix
-export ASAN_OPTIONS="detect_leaks=0"
+export ASAN_OPTIONS="detect_leaks=1"
 
 export LSAN_OPTIONS="suppressions=$(pwd)/test/lsan_suppress.txt"
 export CC