fix for compressed coredumps, please review

From: Alfred Perlstein <alfred_at_freebsd.org>
Date: Fri, 16 Apr 2010 18:16:14 -0700
Can I get a review for this?  

summary:
If doing compressed cores and there is an error, we leak
resources unless this is fixed.


Index: imgact_elf.c
===================================================================
--- imgact_elf.c	(revision 206498)
+++ imgact_elf.c	(working copy)
_at__at_ -29,7 +29,7 _at__at_
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/kern/imgact_elf.c 205643 2010-03-25 14:31:26Z nwhitehorn $");
 
 #include "opt_compat.h"
 #include "opt_core.h"
_at__at_ -1088,8 +1088,10 _at__at_
 	hdrsize = 0;
 	__elfN(puthdr)(td, (void *)NULL, &hdrsize, seginfo.count);
 
-	if (hdrsize + seginfo.size >= limit)
-		return (EFAULT);
+	if (hdrsize + seginfo.size >= limit) {
+		error = EFAULT;
+		goto done;
+	}
 
 	/*
 	 * Allocate memory for building the header, fill it up,
_at__at_ -1097,7 +1099,8 _at__at_
 	 */
 	hdr = malloc(hdrsize, M_TEMP, M_WAITOK);
 	if (hdr == NULL) {
-		return (EINVAL);
+		error = EINVAL;
+		goto done;
 	}
 	error = __elfN(corehdr)(td, vp, cred, seginfo.count, hdr, hdrsize,
 	    gzfile);
_at__at_ -1125,8 +1128,8 _at__at_
 		    curproc->p_comm, error);
 	}
 
+done:
 #ifdef COMPRESS_USER_CORES
-done:
 	if (core_buf)
 		free(core_buf, M_TEMP);
 	if (gzfile)
-- 
- Alfred Perlstein
.- AMA, VMOA #5191, 03 vmax, 92 gs500, 85 ch250
.- FreeBSD committer
Received on Fri Apr 16 2010 - 23:16:14 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:02 UTC