Date: Tue, 10 Dec 2019 20:04:08 +0000 (UTC) From: Eric van Gyzen <vangyzen@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355593 - head/sbin/fsck_ffs Message-ID: <201912102004.xBAK48tS010473@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: vangyzen Date: Tue Dec 10 20:04:08 2019 New Revision: 355593 URL: https://svnweb.freebsd.org/changeset/base/355593 Log: fsck_ffs: fix some memory leaks found by Coverity. Reported by: Coverity CID: 1380549 1380550 1380551 MFC after: 1 week Sponsored by: Dell EMC Isilon Modified: head/sbin/fsck_ffs/setup.c Modified: head/sbin/fsck_ffs/setup.c ============================================================================== --- head/sbin/fsck_ffs/setup.c Tue Dec 10 20:02:57 2019 (r355592) +++ head/sbin/fsck_ffs/setup.c Tue Dec 10 20:04:08 2019 (r355593) @@ -474,11 +474,15 @@ calcsb(char *dev, int devfd, struct fs *fs) if (fsrbuf == NULL) errx(EEXIT, "calcsb: cannot allocate recovery buffer"); if (blread(devfd, fsrbuf, - (SBLOCK_UFS2 - secsize) / dev_bsize, secsize) != 0) + (SBLOCK_UFS2 - secsize) / dev_bsize, secsize) != 0) { + free(fsrbuf); return (0); + } fsr = (struct fsrecovery *)&fsrbuf[secsize - sizeof *fsr]; - if (fsr->fsr_magic != FS_UFS2_MAGIC) + if (fsr->fsr_magic != FS_UFS2_MAGIC) { + free(fsrbuf); return (0); + } memset(fs, 0, sizeof(struct fs)); fs->fs_fpg = fsr->fsr_fpg; fs->fs_fsbtodb = fsr->fsr_fsbtodb; @@ -505,11 +509,14 @@ chkrecovery(int devfd) * Could not determine if backup material exists, so do not * offer to create it. */ + fsrbuf = NULL; if (ioctl(devfd, DIOCGSECTORSIZE, &secsize) == -1 || (fsrbuf = Malloc(secsize)) == NULL || blread(devfd, fsrbuf, (SBLOCK_UFS2 - secsize) / dev_bsize, - secsize) != 0) + secsize) != 0) { + free(fsrbuf); return (1); + } /* * Recovery material has already been created, so do not * need to create it again. @@ -538,12 +545,14 @@ saverecovery(int readfd, int writefd) char *fsrbuf; u_int secsize; + fsrbuf = NULL; if (sblock.fs_magic != FS_UFS2_MAGIC || ioctl(readfd, DIOCGSECTORSIZE, &secsize) == -1 || (fsrbuf = Malloc(secsize)) == NULL || blread(readfd, fsrbuf, (SBLOCK_UFS2 - secsize) / dev_bsize, secsize) != 0) { printf("RECOVERY DATA COULD NOT BE CREATED\n"); + free(fsrbuf); return; } fsr = (struct fsrecovery *)&fsrbuf[secsize - sizeof *fsr];
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912102004.xBAK48tS010473>