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 segfault when run with the
-h or invalid command options:

...

  [  --timeout=<NUM>, -t <NUM> ]        --- timeout value,
Segmentation fault (core dumped)

Fix this by ensuring nvme_root_t object exists before dereferencing
its members and freeing it.

Signed-off-by: Martin George <marting@netapp.com>
  • Loading branch information
martin-gpy committed Jun 29, 2024
1 parent e42b6a8 commit 78288da
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,17 @@ void nvme_free_tree(nvme_root_t r)
{
struct nvme_host *h, *_h;

free(r->options);
nvme_for_each_host_safe(r, h, _h)
__nvme_free_host(h);
if (r->config_file)
free(r->config_file);
if (r->application)
free(r->application);
free(r);
if (r) {
if (r->options)
free(r->options);
nvme_for_each_host_safe(r, h, _h)
__nvme_free_host(h);
if (r->config_file)
free(r->config_file);
if (r->application)
free(r->application);
free(r);
}
}

void nvme_root_release_fds(nvme_root_t r)
Expand Down

0 comments on commit 78288da

Please sign in to comment.