]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
tree: missing closedir() causes fd leak for "/sys/bus/pci/slots"
authorMartin Belanger <martin.belanger@dell.com>
Wed, 5 Jul 2023 14:59:25 +0000 (10:59 -0400)
committerDaniel Wagner <wagi@monom.org>
Wed, 5 Jul 2023 16:00:23 +0000 (18:00 +0200)
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>
src/nvme/tree.c

index a2ac0698e59ac8eeb042b5f8e0a93f007b901c42..805eff994a1e8ccdd9ccac25102e74445840948e 100644 (file)
@@ -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");
@@ -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;