Skip to content

Commit

Permalink
tree: fix segfault in nvme_free_tree()
Browse files Browse the repository at this point in the history
Commands like nvme list & list-subsys currently segfault for --help or
any invalid command option as shown below:

nvme list -h
Usage: nvme list <device> [OPTIONS]

Retrieve basic information for all NVMe namespaces

Options:
  [  --verbose, -v ]                    --- output verbosity
  [  --output-format=<FMT>, -o <FMT> ]  --- format: normal|json|binary
Segmentation fault (core dumped)

This is due to an invalid dereferencing of the nvme_root_t object in
nvme_free_tree(). Fix this by checking whether this object is valid
before dereferencing and freeing it. And while we are it, ensure
r->options is also valid before freeing it.

Signed-off-by: Martin George <marting@netapp.com>
  • Loading branch information
martin-gpy authored and igaw committed Jul 1, 2024
1 parent e42b6a8 commit 6d3dbd9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ void nvme_free_tree(nvme_root_t r)
{
struct nvme_host *h, *_h;

free(r->options);
if (!r)
return;

if (r->options)
free(r->options);
nvme_for_each_host_safe(r, h, _h)
__nvme_free_host(h);
if (r->config_file)
Expand Down

0 comments on commit 6d3dbd9

Please sign in to comment.