Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 May 2018 14:23:11 +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: r334240 - head/sys/kern
Message-ID:  <201805261423.w4QENBjm009082@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: vangyzen
Date: Sat May 26 14:23:11 2018
New Revision: 334240
URL: https://svnweb.freebsd.org/changeset/base/334240

Log:
  kern_cpuset: fix small leak on error path
  
  The "mask" was leaked on some error paths.
  
  Reported by:	Coverity
  CID:		1384683
  Sponsored by:	Dell EMC

Modified:
  head/sys/kern/kern_cpuset.c

Modified: head/sys/kern/kern_cpuset.c
==============================================================================
--- head/sys/kern/kern_cpuset.c	Sat May 26 14:14:56 2018	(r334239)
+++ head/sys/kern/kern_cpuset.c	Sat May 26 14:23:11 2018	(r334240)
@@ -2038,6 +2038,9 @@ kern_cpuset_setdomain(struct thread *td, cpulevel_t le
 	if (domainsetsize < sizeof(domainset_t) ||
 	    domainsetsize > DOMAINSET_MAXSIZE / NBBY)
 		return (ERANGE);
+	if (policy <= DOMAINSET_POLICY_INVALID ||
+	    policy > DOMAINSET_POLICY_MAX)
+		return (EINVAL);
 	/* In Capability mode, you can only set your own CPU set. */
 	if (IN_CAPABILITY_MODE(td)) {
 		if (level != CPU_LEVEL_WHICH)
@@ -2071,15 +2074,14 @@ kern_cpuset_setdomain(struct thread *td, cpulevel_t le
 	}
 	DOMAINSET_COPY(mask, &domain.ds_mask);
 	domain.ds_policy = policy;
-	if (policy <= DOMAINSET_POLICY_INVALID ||
-	    policy > DOMAINSET_POLICY_MAX)
-		return (EINVAL);
 
 	/* Translate preferred policy into a mask and fallback. */
 	if (policy == DOMAINSET_POLICY_PREFER) {
 		/* Only support a single preferred domain. */
-		if (DOMAINSET_COUNT(&domain.ds_mask) != 1)
-			return (EINVAL);
+		if (DOMAINSET_COUNT(&domain.ds_mask) != 1) {
+			error = EINVAL;
+			goto out;
+		}
 		domain.ds_prefer = DOMAINSET_FFS(&domain.ds_mask) - 1;
 		/* This will be constrained by domainset_shadow(). */
 		DOMAINSET_FILL(&domain.ds_mask);



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