Skip to content

Commit c434d43

Browse files
authored
Merge pull request #233 from igaw/fix-mem-leak
tree: Fix memleaks in __nvme_free_ns() and nvme_scan_subsystem()
2 parents 6d38953 + 0c250e9 commit c434d43

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

libnvme/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ if have_python_support
5555
test_env = environment()
5656
test_env.append('MALLOC_PERTURB_', '0')
5757
test_env.append('PYTHONPATH', join_paths(meson.current_build_dir(), '..'))
58+
test_env.append('PYTHONMALLOC', 'malloc')
5859

5960
# Test section
6061
test('[Python] import libnvme', python3, args: ['-c', 'from libnvme import nvme'], env: test_env)

src/nvme/tree.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ static void __nvme_free_ns(struct nvme_ns *n)
305305
{
306306
list_del_init(&n->entry);
307307
close(n->fd);
308+
free(n->generic_name);
308309
free(n->name);
309310
free(n->sysfs_dir);
310311
free(n);
@@ -511,24 +512,26 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
511512
if (!h)
512513
h = nvme_default_host(r);
513514
if (!h) {
515+
free(path);
514516
errno = ENOMEM;
515517
return -1;
516518
}
517519
subsysnqn = nvme_get_attr(path, "subsysnqn");
520+
free(path);
518521
if (!subsysnqn) {
519522
errno = ENODEV;
520-
goto free_path;
523+
return -1;
521524
}
522525
s = nvme_lookup_subsystem(h, name, subsysnqn);
523526
free(subsysnqn);
524527
if (!s) {
525528
errno = ENOMEM;
526-
goto free_path;
529+
return -1;
527530
}
528531
if (!s->name) {
529532
ret = nvme_init_subsystem(s, name);
530533
if (ret < 0)
531-
goto free_path;
534+
return -1;
532535
}
533536

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

541544
return 0;
542-
543-
free_path:
544-
free(path);
545-
return -1;
546545
}
547546

548547
nvme_ctrl_t nvme_path_get_ctrl(nvme_path_t p)

0 commit comments

Comments
 (0)