Skip to content

Commit

Permalink
tree: missing closedir() causes fd leak for "/sys/bus/pci/slots"
Browse files Browse the repository at this point in the history
In nvme_ctrl_lookup_phy_slot(), we are missing a closedir(), which
causes file descriptors to leak. Also, there was a missing free()
when the function returns with ENOMEM.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
  • Loading branch information
Martin Belanger authored and igaw committed Jul 5, 2023
1 parent bf6ec01 commit c56910f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,8 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address)
ret = asprintf(&path, "/sys/bus/pci/slots/%s", entry->d_name);
if (ret < 0) {
errno = ENOMEM;
free(target_addr);
closedir(slots_dir);
return NULL;
}
addr = nvme_get_attr(path, "address");
Expand All @@ -1306,6 +1308,7 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address)
}
}
free(target_addr);
closedir(slots_dir);
if (found)
return strdup(entry->d_name);
return NULL;
Expand Down

0 comments on commit c56910f

Please sign in to comment.