Skip to content

Commit

Permalink
Merge pull request #233 from igaw/fix-mem-leak
Browse files Browse the repository at this point in the history
tree: Fix memleaks in __nvme_free_ns() and nvme_scan_subsystem()
  • Loading branch information
igaw authored Feb 11, 2022
2 parents 6d38953 + 0c250e9 commit c434d43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions libnvme/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if have_python_support
test_env = environment()
test_env.append('MALLOC_PERTURB_', '0')
test_env.append('PYTHONPATH', join_paths(meson.current_build_dir(), '..'))
test_env.append('PYTHONMALLOC', 'malloc')

# Test section
test('[Python] import libnvme', python3, args: ['-c', 'from libnvme import nvme'], env: test_env)
Expand Down
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 c434d43

Please sign in to comment.