]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix userspace memory leaks found by Clang Static Analzyer
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Tue, 27 Sep 2022 00:18:05 +0000 (20:18 -0400)
committerGitHub <noreply@github.com>
Tue, 27 Sep 2022 00:18:05 +0000 (17:18 -0700)
Recently, I have been making a push to fix things that coverity found.
However, I was curious what Clang's static analyzer reported, so I ran
it and found things that coverity had missed.

* contrib/pam_zfs_key/pam_zfs_key.c: If prop_mountpoint is passed more
  than once, we leak memory.
* module/zfs/zcp_get.c: We leak memory on temporary properties in
  userspace.
* tests/zfs-tests/cmd/draid.c: On error from vdev_draid_rand(), we leak
  memory if best_map had been allocated by a prior iteration.
* tests/zfs-tests/cmd/mkfile.c: Memory used by the loop is not freed
  before program termination.

Arguably, these are all minor issues, but if we ignore them, then they
could obscure serious bugs, so we fix them.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13955

contrib/pam_zfs_key/pam_zfs_key.c
module/zfs/zcp_get.c
tests/zfs-tests/cmd/draid.c
tests/zfs-tests/cmd/mkfile.c

index c1001e6b81c226ebeefead667b1d817a207d9f73..aaca670080b838ccb22f35001e21719da654c04a 100644 (file)
@@ -480,7 +480,8 @@ zfs_key_config_load(pam_handle_t *pamh, zfs_key_config_t *config,
                } else if (strcmp(argv[c], "nounmount") == 0) {
                        config->unmount_and_unload = 0;
                } else if (strcmp(argv[c], "prop_mountpoint") == 0) {
-                       config->homedir = strdup(entry->pw_dir);
+                       if (config->homedir == NULL)
+                               config->homedir = strdup(entry->pw_dir);
                }
        }
        return (0);
index 0a0466d46969716d21b4d9e65405f57fe4ab277b..8230a419366277db356e2a5096ae574722e39b0f 100644 (file)
@@ -472,6 +472,7 @@ get_zap_prop(lua_State *state, dsl_dataset_t *ds, zfs_prop_t zfs_prop)
                /* Fill in temporary value for prop, if applicable */
                (void) zfs_get_temporary_prop(ds, zfs_prop, &numval, setpoint);
 #else
+               kmem_free(strval, ZAP_MAXVALUELEN);
                return (luaL_error(state,
                    "temporary properties only supported in kernel mode",
                    prop_name));
index 869ca902d0832fbfdcef7d1d874a0f0ec5920340..39b58a709cec3547a22b5a26ba6fd83a08f6f8b4 100644 (file)
@@ -720,8 +720,11 @@ eval_maps(uint64_t children, int passes, uint64_t *map_seed,
                 */
                error = alloc_new_map(children, MAP_ROWS_DEFAULT,
                    vdev_draid_rand(map_seed), &map);
-               if (error)
+               if (error) {
+                       if (best_map != NULL)
+                               free_map(best_map);
                        return (error);
+               }
 
                /*
                 * Consider maps with a lower worst_ratio to be of higher
index 7ce50e6a37c454d6c84b5d79f0faea709873525b..3b61deed6bf5d4939131fdc46f0a495df04bcc2e 100644 (file)
@@ -276,5 +276,9 @@ main(int argc, char **argv)
                argv++;
                argc--;
        }
+
+       if (buf)
+               free(buf);
+
        return (errors);
 }