Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Sep 2002 09:20:23 +0200
From:      Poul-Henning Kamp <phk@freebsd.org>
To:        audit@freebsd.org, current@freebsd.org
Subject:   PATCH: various memory leaks.
Message-ID:  <59914.1033370423@critter.freebsd.dk>

next in thread | raw e-mail | index | archive | help

I went through the FlexeLint output of the LINT kernel on i386 and
tried to examine all warnings about memoryleaks in central or
semi-central code.

I this patch I belive addresses the ones I think I could confirm,
in the following files:
	cam/scsi/scsi_cd.c
	cam/scsi/scsi_da.c
	dev/ata/ata-all.c
	fs/pseudofs/pseudofs_vncache.c
	fs/umapfs/umap_vfsops.c
	kern/kern_ktrace.c
	kern/kern_linker.c
	ufs/ufs/ufs_vnops.c

I would appreciate if the respective owners, authors, maintainers
etc would review and commit their own bits from this patch.

Thanks in advance!

Poul-Henning


Index: cam/scsi/scsi_cd.c
===================================================================
RCS file: /home/ncvs/src/sys/cam/scsi/scsi_cd.c,v
retrieving revision 1.61
diff -u -r1.61 scsi_cd.c
--- cam/scsi/scsi_cd.c	28 Sep 2002 17:14:05 -0000	1.61
+++ cam/scsi/scsi_cd.c	30 Sep 2002 06:11:54 -0000
@@ -1463,6 +1463,7 @@
 		start_ccb->ccb_h.ccb_bp = NULL;
 		start_ccb->ccb_h.ccb_state = CD_CCB_PROBE;
 		xpt_action(start_ccb);
+		/* XXX missing free(rcap, M_TEMP) ??? */
 		break;
 	}
 	}
Index: cam/scsi/scsi_da.c
===================================================================
RCS file: /home/ncvs/src/sys/cam/scsi/scsi_da.c,v
retrieving revision 1.108
diff -u -r1.108 scsi_da.c
--- cam/scsi/scsi_da.c	20 Sep 2002 19:35:52 -0000	1.108
+++ cam/scsi/scsi_da.c	30 Sep 2002 06:13:35 -0000
@@ -1249,6 +1249,7 @@
 		start_ccb->ccb_h.ccb_bp = NULL;
 		start_ccb->ccb_h.ccb_state = DA_CCB_PROBE;
 		xpt_action(start_ccb);
+		/* XXX missing free(rcap, M_TEMP) ?? */
 		break;
 	}
 	}
Index: dev/ata/ata-all.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/ata/ata-all.c,v
retrieving revision 1.154
diff -u -r1.154 ata-all.c
--- dev/ata/ata-all.c	12 Sep 2002 14:32:33 -0000	1.154
+++ dev/ata/ata-all.c	30 Sep 2002 06:19:11 -0000
@@ -454,8 +454,10 @@
 
 	    if (iocmd->u.atapi.flags & ATAPI_CMD_WRITE) {
 		error = copyin(iocmd->u.atapi.data, buf, iocmd->u.atapi.count);
-		if (error)
+		if (error) {
+		    free(buf, M_ATA);
 		    return error;
+		}
 	    }
 	    error = atapi_queue_cmd(atadev, iocmd->u.atapi.ccb,
 				    buf, iocmd->u.atapi.count,
Index: fs/pseudofs/pseudofs_vncache.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/pseudofs/pseudofs_vncache.c,v
retrieving revision 1.17
diff -u -r1.17 pseudofs_vncache.c
--- fs/pseudofs/pseudofs_vncache.c	14 Sep 2002 09:02:24 -0000	1.17
+++ fs/pseudofs/pseudofs_vncache.c	30 Sep 2002 06:23:59 -0000
@@ -136,8 +136,10 @@
 	if (++pfs_vncache_entries > pfs_vncache_maxentries)
 		pfs_vncache_maxentries = pfs_vncache_entries;
 	error = getnewvnode("pseudofs", mp, pfs_vnodeop_p, vpp);
-	if (error)
+	if (error) {
+		FREE(pvd, M_PFSVNCACHE);
 		return (error);
+	}
 	pvd->pvd_pn = pn;
 	pvd->pvd_pid = pid;
 	(*vpp)->v_data = pvd;
Index: fs/umapfs/umap_vfsops.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/umapfs/umap_vfsops.c,v
retrieving revision 1.46
diff -u -r1.46 umap_vfsops.c
--- fs/umapfs/umap_vfsops.c	4 Aug 2002 10:29:31 -0000	1.46
+++ fs/umapfs/umap_vfsops.c	30 Sep 2002 06:26:18 -0000
@@ -170,6 +170,8 @@
 	if (args.nentries > MAPFILEENTRIES || args.gnentries >
 	    GMAPFILEENTRIES) {
 		vput(lowerrootvp);
+		free(amp, M_UMAPFSMNT);
+		/* XXX missing error = EINVAL ? */
 		return (error);
 	}
 
@@ -177,8 +179,10 @@
 	amp->info_gnentries = args.gnentries;
 	error = copyin(args.mapdata, (caddr_t)amp->info_mapdata,
 	    2*sizeof(u_long)*args.nentries);
-	if (error)
+	if (error) {
+		free(amp, M_UMAPFSMNT);
 		return (error);
+	}
 
 #ifdef DEBUG
 	printf("umap_mount:nentries %d\n",args.nentries);
@@ -189,8 +193,10 @@
 
 	error = copyin(args.gmapdata, (caddr_t)amp->info_gmapdata,
 	    2*sizeof(u_long)*args.gnentries);
-	if (error)
+	if (error) {
+		free(amp, M_UMAPFSMNT);
 		return (error);
+	}
 
 #ifdef DEBUG
 	printf("umap_mount:gnentries %d\n",args.gnentries);
Index: kern/kern_ktrace.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_ktrace.c,v
retrieving revision 1.77
diff -u -r1.77 kern_ktrace.c
--- kern/kern_ktrace.c	11 Sep 2002 21:00:56 -0000	1.77
+++ kern/kern_ktrace.c	30 Sep 2002 06:35:00 -0000
@@ -325,8 +325,11 @@
 		bcopy(args, buf, buflen);
 	}
 	req = ktr_getrequest(KTR_SYSCALL);
-	if (req == NULL)
+	if (req == NULL) {
+		if (buf != NULL)
+			free(buf, M_KTRACE);
 		return;
+	}
 	ktp = &req->ktr_data.ktr_syscall;
 	ktp->ktr_code = code;
 	ktp->ktr_narg = narg;
@@ -372,8 +375,11 @@
 		bcopy(path, buf, namelen);
 	}
 	req = ktr_getrequest(KTR_NAMEI);
-	if (req == NULL)
+	if (req == NULL) {
+		if (buf != NULL)
+			free(buf, M_KTRACE);
 		return;
+	}
 	if (namelen > 0) {
 		req->ktr_header.ktr_len = namelen;
 		req->ktr_header.ktr_buffer = buf;
@@ -621,11 +627,15 @@
 		return (EINVAL);
 	cp = malloc(uap->len, M_KTRACE, M_WAITOK);
 	error = copyin(uap->addr, cp, uap->len);
-	if (error)
+	if (error) {
+		free(cp, M_KTRACE);
 		return (error);
+	}
 	req = ktr_getrequest(KTR_USER);
-	if (req == NULL)
+	if (req == NULL) {
+		free(cp, M_KTRACE);
 		return (0);
+	}
 	req->ktr_header.ktr_buffer = cp;
 	req->ktr_header.ktr_len = uap->len;
 	ktr_submitrequest(req);
Index: kern/kern_linker.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_linker.c,v
retrieving revision 1.94
diff -u -r1.94 kern_linker.c
--- kern/kern_linker.c	15 Aug 2002 20:55:03 -0000	1.94
+++ kern/kern_linker.c	30 Sep 2002 06:36:15 -0000
@@ -1531,6 +1531,7 @@
 		printf("warning: KLD '%s' is newer than the linker.hints"
 		    " file\n", result);
 bad:
+	free(pathbuf, M_LINKER);
 	if (hints)
 		free(hints, M_TEMP);
 	if (nd.ni_vp != NULL) {
Index: ufs/ufs/ufs_vnops.c
===================================================================
RCS file: /home/ncvs/src/sys/ufs/ufs/ufs_vnops.c,v
retrieving revision 1.210
diff -u -r1.210 ufs_vnops.c
--- ufs/ufs/ufs_vnops.c	28 Sep 2002 17:15:31 -0000	1.210
+++ ufs/ufs/ufs_vnops.c	30 Sep 2002 07:06:33 -0000
@@ -1480,6 +1480,8 @@
 	default:
 		UFS_VFREE(tvp, ip->i_number, dmode);
 		vput(tvp);
+		FREE(acl, M_ACL);
+		FREE(dacl, M_ACL);
 		return (error);
 	}
 #else /* !UFS_ACL */
@@ -2381,6 +2383,8 @@
 	default:
 		UFS_VFREE(tvp, ip->i_number, mode);
 		vput(tvp);
+		FREE(acl, M_ACL);
+		acl = NULL;
 		return (error);
 	}
 #else /* !UFS_ACL */

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?59914.1033370423>