summaryrefslogtreecommitdiffstats
path: root/fdisk/sfdisk.c
diff options
context:
space:
mode:
authorKarel Zak2012-02-02 12:44:27 +0100
committerKarel Zak2012-02-02 12:44:27 +0100
commit574d9252a1dd310374e6d419f294cfcc461894e5 (patch)
treeb773d238fdb263114b9bf7685c032cbd05e60f4e /fdisk/sfdisk.c
parentsfdisk: fix typo in cdrom detection (diff)
downloadkernel-qcow2-util-linux-574d9252a1dd310374e6d419f294cfcc461894e5.tar.gz
kernel-qcow2-util-linux-574d9252a1dd310374e6d419f294cfcc461894e5.tar.xz
kernel-qcow2-util-linux-574d9252a1dd310374e6d419f294cfcc461894e5.zip
sfdisk: cleanup fd usage
Diffstat (limited to 'fdisk/sfdisk.c')
-rw-r--r--fdisk/sfdisk.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
index 23e880b2b..a07f81110 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"));