Skip to content

Commit 5bb5c8f

Browse files
martin-gpyigaw
authored andcommitted
tree: fix segfault in nvme_free_tree()
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 <[email protected]>
1 parent e42b6a8 commit 5bb5c8f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/nvme/tree.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@ void nvme_free_tree(nvme_root_t r)
377377
{
378378
struct nvme_host *h, *_h;
379379

380-
free(r->options);
380+
if (!r)
381+
return;
382+
383+
if (r->options)
384+
free(r->options);
381385
nvme_for_each_host_safe(r, h, _h)
382386
__nvme_free_host(h);
383387
if (r->config_file)

0 commit comments

Comments
 (0)