[syslinux:master] chain: add missing pi_del() in find*() functions

syslinux-bot for Michal Soltys soltys at ziu.info
Tue Aug 26 19:00:10 PDT 2014


Commit-ID:  68e8acb564a1b0e591d73edb912aa703c54ba2df
Gitweb:     http://www.syslinux.org/commit/68e8acb564a1b0e591d73edb912aa703c54ba2df
Author:     Michal Soltys <soltys at ziu.info>
AuthorDate: Sun, 29 Jun 2014 21:41:41 +0200
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Tue, 26 Aug 2014 18:07:18 -0700

chain: add missing pi_del() in find*() functions

As partiter doesn't deallocate itself after finish (anymore), it should
be deleted after each loop iteration.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>

---
 com32/chain/chain.c | 60 ++++++++++++++++++++++-------------------------------
 1 file changed, 25 insertions(+), 35 deletions(-)

diff --git a/com32/chain/chain.c b/com32/chain/chain.c
index c08ec6e..f86cd7d 100644
--- a/com32/chain/chain.c
+++ b/com32/chain/chain.c
@@ -64,27 +64,23 @@ static int is_phys(uint8_t sdifs)
 static int find_by_sig(uint32_t mbr_sig,
 			struct part_iter **_boot_part)
 {
-    struct part_iter *boot_part = NULL;
+    struct part_iter *iter = NULL;
     struct disk_info diskinfo;
     int drive;
 
     for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) {
 	if (disk_get_params(drive, &diskinfo))
 	    continue;		/* Drive doesn't exist */
-	if (!(boot_part = pi_begin(&diskinfo, opt.piflags)))
-	    continue;
-	/* Check for a MBR disk */
-	if (boot_part->type != typedos) {
-	    pi_del(&boot_part);
+	if (!(iter = pi_begin(&diskinfo, opt.piflags)))
 	    continue;
-	}
-	if (boot_part->dos.disk_sig == mbr_sig) {
+	/* Check for a matching MBR disk */
+	if (iter->type == typedos && iter->dos.disk_sig == mbr_sig)
 	    goto ok;
-	}
+	pi_del(&iter);
     }
     drive = -1;
 ok:
-    *_boot_part = boot_part;
+    *_boot_part = iter;
     return drive;
 }
 
@@ -95,29 +91,26 @@ ok:
 static int find_by_guid(const struct guid *gpt_guid,
 			struct part_iter **_boot_part)
 {
-    struct part_iter *boot_part = NULL;
+    struct part_iter *iter = NULL;
     struct disk_info diskinfo;
     int drive;
 
     for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) {
 	if (disk_get_params(drive, &diskinfo))
 	    continue;		/* Drive doesn't exist */
-	if (!(boot_part = pi_begin(&diskinfo, opt.piflags)))
-	    continue;
-	/* Check for a GPT disk */
-	if (boot_part->type != typegpt) {
-	    pi_del(&boot_part);
+	if (!(iter = pi_begin(&diskinfo, opt.piflags)))
 	    continue;
-	}
 	/* Check for a matching GPT disk/partition guid */
-	do {
-	    if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof *gpt_guid))
-		goto ok;
-	} while (!pi_next(boot_part));
+	if (iter->type == typegpt)
+	    do {
+		if (!memcmp(&iter->gpt.part_guid, gpt_guid, sizeof *gpt_guid))
+		    goto ok;
+	    } while (!pi_next(iter));
+	pi_del(&iter);
     }
     drive = -1;
 ok:
-    *_boot_part = boot_part;
+    *_boot_part = iter;
     return drive;
 }
 
@@ -127,29 +120,26 @@ ok:
  */
 static int find_by_label(const char *label, struct part_iter **_boot_part)
 {
-    struct part_iter *boot_part = NULL;
+    struct part_iter *iter = NULL;
     struct disk_info diskinfo;
     int drive;
 
     for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) {
 	if (disk_get_params(drive, &diskinfo))
 	    continue;		/* Drive doesn't exist */
-	if (!(boot_part = pi_begin(&diskinfo, opt.piflags)))
-	    continue;
-	/* Check for a GPT disk */
-	if (!(boot_part->type == typegpt)) {
-	    pi_del(&boot_part);
+	if (!(iter = pi_begin(&diskinfo, opt.piflags)))
 	    continue;
-	}
-	/* Check for a matching partition */
-	while (!pi_next(boot_part)) {
-	    if (!strcmp(label, boot_part->gpt.part_label))
-		goto ok;
-	}
+	/* Check for a matching GPT partition label */
+	if (iter->type == typegpt)
+	    while (!pi_next(iter)) {
+		if (!strcmp(label, iter->gpt.part_label))
+		    goto ok;
+	    }
+	pi_del(&iter);
     }
     drive = -1;
 ok:
-    *_boot_part = boot_part;
+    *_boot_part = iter;
     return drive;
 }
 


More information about the Syslinux-commits mailing list