From: Karel Zak Date: Thu, 2 Feb 2012 11:44:27 +0000 (+0100) Subject: sfdisk: cleanup fd usage X-Git-Tag: v2.21-rc2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=574d9252a1dd310374e6d419f294cfcc461894e5;p=thirdparty%2Futil-linux.git sfdisk: cleanup fd usage --- diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index 23e880b2b8..a07f81110b 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -344,7 +344,7 @@ restore_sectors(char *dev) { } free(ss0); - if (!reread_disk_partition(dev, fdout)) + if (!reread_disk_partition(dev, fdout)) /* closes fdout */ goto err; close(fdin); @@ -3102,7 +3102,7 @@ do_change_id(char *dev, char *pnam, char *id) { pno = asc_to_index(pnam, z); if (id == 0) { printf("%x\n", z->partitions[pno].p.sys_type); - return; + goto done; } i = strtoul(id, NULL, 16); if (i > 255) @@ -3114,6 +3114,7 @@ do_change_id(char *dev, char *pnam, char *id) { else exit_status = 1; +done: close(fd); } @@ -3224,9 +3225,10 @@ do_fdisk(char *dev) { else exit_status = 1; - if (!reread_disk_partition(dev, fd)) + if (!reread_disk_partition(dev, fd)) { /* close fd on success */ + close(fd); exit_status = 1; - + } my_warn(_("If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)\n" "to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1\n" "(See fdisk(8).)\n"));