summaryrefslogtreecommitdiffstats
path: root/sbin/i386
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2000-07-15 13:37:47 +0000
committerache <ache@FreeBSD.org>2000-07-15 13:37:47 +0000
commitfce096f2b7fa190448d60083bf35b66aec6e6a18 (patch)
treeb802e04edc85b0b5ffe2e6cef9bfff390c9490f3 /sbin/i386
parent0eaece4ce759f0641320fa29646cd6f088ef74de (diff)
downloadFreeBSD-src-fce096f2b7fa190448d60083bf35b66aec6e6a18.zip
FreeBSD-src-fce096f2b7fa190448d60083bf35b66aec6e6a18.tar.gz
Fix memory leak/double free found by phkmalloc
Uniform mboot.bootinst allocation code to be independent of functions order
Diffstat (limited to 'sbin/i386')
-rw-r--r--sbin/i386/fdisk/fdisk.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/sbin/i386/fdisk/fdisk.c b/sbin/i386/fdisk/fdisk.c
index dc0b5de..acbd6ae 100644
--- a/sbin/i386/fdisk/fdisk.c
+++ b/sbin/i386/fdisk/fdisk.c
@@ -299,10 +299,11 @@ main(int argc, char *argv[])
}
/* (abu)use mboot.bootinst to probe for the sector size */
+ if (mboot.bootinst != NULL)
+ free(mboot.bootinst);
if ((mboot.bootinst = malloc(MAX_SEC_SIZE)) == NULL)
err(1, "cannot allocate buffer to determine disk sector size");
read_disk(0, mboot.bootinst);
- free(mboot.bootinst);
if (s_flag)
{
@@ -494,6 +495,8 @@ init_boot(void)
err(1, "%s", fname);
if ((mboot.bootinst_size = sb.st_size) % secsize != 0)
errx(1, "%s: length must be a multiple of sector size", fname);
+ if (mboot.bootinst != NULL)
+ free(mboot.bootinst);
if ((mboot.bootinst = malloc(mboot.bootinst_size = sb.st_size)) == NULL)
errx(1, "%s: unable to allocate read buffer", fname);
if ((n = read(fd, mboot.bootinst, mboot.bootinst_size)) == -1 ||
@@ -779,14 +782,13 @@ get_params()
static int
read_s0()
{
- if (mboot.bootinst != NULL) {
+ mboot.bootinst_size = secsize;
+ if (mboot.bootinst != NULL)
free(mboot.bootinst);
- mboot.bootinst_size = secsize;
- if ((mboot.bootinst = malloc(mboot.bootinst_size)) == NULL) {
- warnx("unable to allocate buffer to read fdisk "
- "partition table");
- return -1;
- }
+ if ((mboot.bootinst = malloc(mboot.bootinst_size)) == NULL) {
+ warnx("unable to allocate buffer to read fdisk "
+ "partition table");
+ return -1;
}
if (read_disk(0, mboot.bootinst) == -1) {
warnx("can't read fdisk partition table");
OpenPOWER on IntegriCloud