]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
{platform,super}-intel: Fix two resource leaks
authorJes Sorensen <Jes.Sorensen@redhat.com>
Mon, 7 Mar 2016 17:33:49 +0000 (12:33 -0500)
committerJes Sorensen <Jes.Sorensen@redhat.com>
Wed, 9 Mar 2016 16:35:34 +0000 (11:35 -0500)
The code did not free 'dir' allocated by opendir(). An additional
benefit is that this simplifies the for() loops.

Fixes: 60f0f54d ("IMSM: Add support for VMD")
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
platform-intel.c
super-intel.c

index 88818f340b1311b038a433f4dbbe4a29b0f96a21..c60fd9e3bc63c471b8669f64da807c0aa9a8b51c 100644 (file)
@@ -724,8 +724,10 @@ char *vmd_domain_to_controller(struct sys_dev *hba, char *buf)
                return NULL;
 
        dir = opendir("/sys/bus/pci/drivers/vmd");
+       if (!dir)
+               return NULL;
 
-       for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) {
+       for (ent = readdir(dir); ent; ent = readdir(dir)) {
                sprintf(path, "/sys/bus/pci/drivers/vmd/%s/domain/device",
                        ent->d_name);
 
@@ -734,8 +736,11 @@ char *vmd_domain_to_controller(struct sys_dev *hba, char *buf)
 
                if (strncmp(buf, hba->path, strlen(buf)) == 0) {
                        sprintf(path, "/sys/bus/pci/drivers/vmd/%s", ent->d_name);
+                       closedir(dir);
                        return realpath(path, buf);
                }
        }
+
+       closedir(dir);
        return NULL;
 }
index 158f4e84606998c19d26fe2e15d06875303262a0..e1bee7573e3b1692edbc9127c4c8ce81f34d0d6f 100644 (file)
@@ -1781,7 +1781,10 @@ static int print_vmd_attached_devs(struct sys_dev *hba)
         * this hba
         */
        dir = opendir("/sys/bus/pci/drivers/nvme");
-       for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) {
+       if (!dir)
+               return 1;
+
+       for (ent = readdir(dir); ent; ent = readdir(dir)) {
                int n;
 
                /* is 'ent' a device? check that the 'subsystem' link exists and
@@ -1814,6 +1817,7 @@ static int print_vmd_attached_devs(struct sys_dev *hba)
                free(rp);
        }
 
+       closedir(dir);
        return 0;
 }