Skip to content

Commit

Permalink
tree: Fix memleaks in __nvme_free_ns() and nvme_scan_subsystem()
Browse files Browse the repository at this point in the history
valgrind reports that we are leaking memory in __nvme_free_ns() and
nvme_scan_subsystem(). Free ns->generic_name and path which makes
valgrind also happy.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
  • Loading branch information
igaw committed Feb 11, 2022
1 parent 6d38953 commit 4874da7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ static void __nvme_free_ns(struct nvme_ns *n)
{
list_del_init(&n->entry);
close(n->fd);
free(n->generic_name);
free(n->name);
free(n->sysfs_dir);
free(n);
Expand Down Expand Up @@ -511,24 +512,26 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
if (!h)
h = nvme_default_host(r);
if (!h) {
free(path);
errno = ENOMEM;
return -1;
}
subsysnqn = nvme_get_attr(path, "subsysnqn");
free(path);
if (!subsysnqn) {
errno = ENODEV;
goto free_path;
return -1;
}
s = nvme_lookup_subsystem(h, name, subsysnqn);
free(subsysnqn);
if (!s) {
errno = ENOMEM;
goto free_path;
return -1;
}
if (!s->name) {
ret = nvme_init_subsystem(s, name);
if (ret < 0)
goto free_path;
return -1;
}

nvme_subsystem_scan_namespaces(r, s);
Expand All @@ -539,10 +542,6 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
}

return 0;

free_path:
free(path);
return -1;
}

nvme_ctrl_t nvme_path_get_ctrl(nvme_path_t p)
Expand Down

0 comments on commit 4874da7

Please sign in to comment.