From owner-svn-src-head@FreeBSD.ORG Wed Jan 22 15:44:39 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 74266ECD; Wed, 22 Jan 2014 15:44:39 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 45EED1567; Wed, 22 Jan 2014 15:44:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s0MFidep073071; Wed, 22 Jan 2014 15:44:39 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s0MFidkr073070; Wed, 22 Jan 2014 15:44:39 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201401221544.s0MFidkr073070@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 22 Jan 2014 15:44:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r261028 - head/sys/netpfil/pf X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jan 2014 15:44:39 -0000 Author: glebius Date: Wed Jan 22 15:44:38 2014 New Revision: 261028 URL: http://svnweb.freebsd.org/changeset/base/261028 Log: Fix resource leak and simplify code for DIOCCHANGEADDR. CID: 1007035 Modified: head/sys/netpfil/pf/pf_ioctl.c Modified: head/sys/netpfil/pf/pf_ioctl.c ============================================================================== --- head/sys/netpfil/pf/pf_ioctl.c Wed Jan 22 14:22:44 2014 (r261027) +++ head/sys/netpfil/pf/pf_ioctl.c Wed Jan 22 15:44:38 2014 (r261028) @@ -2281,6 +2281,7 @@ DIOCGETSTATES_full: bcopy(&pca->addr, newpa, sizeof(struct pf_pooladdr)); if (newpa->ifname[0]) kif = malloc(sizeof(*kif), PFI_MTYPE, M_WAITOK); + newpa->kif = NULL; } #define ERROUT(x) { error = (x); goto DIOCCHANGEADDR_error; } @@ -2298,8 +2299,8 @@ DIOCGETSTATES_full: if (newpa->ifname[0]) { newpa->kif = pfi_kif_attach(kif, newpa->ifname); pfi_kif_ref(newpa->kif); - } else - newpa->kif = NULL; + kif = NULL; + } switch (newpa->addr.type) { case PF_ADDR_DYNIFTL: @@ -2313,32 +2314,24 @@ DIOCGETSTATES_full: error = ENOMEM; break; } - if (error) { - if (newpa->kif) - pfi_kif_unref(newpa->kif); - PF_RULES_WUNLOCK(); - free(newpa, M_PFRULE); - break; - } + if (error) + goto DIOCCHANGEADDR_error; } - if (pca->action == PF_CHANGE_ADD_HEAD) + switch (pca->action) { + case PF_CHANGE_ADD_HEAD: oldpa = TAILQ_FIRST(&pool->list); - else if (pca->action == PF_CHANGE_ADD_TAIL) + break; + case PF_CHANGE_ADD_TAIL: oldpa = TAILQ_LAST(&pool->list, pf_palist); - else { - int i = 0; - + break; + default: oldpa = TAILQ_FIRST(&pool->list); - while ((oldpa != NULL) && (i < pca->nr)) { + for (int i = 0; oldpa && i < pca->nr; i++) oldpa = TAILQ_NEXT(oldpa, entries); - i++; - } - if (oldpa == NULL) { - PF_RULES_WUNLOCK(); - error = EINVAL; - break; - } + + if (oldpa == NULL) + ERROUT(EINVAL); } if (pca->action == PF_CHANGE_REMOVE) { @@ -2366,13 +2359,14 @@ DIOCGETSTATES_full: } pool->cur = TAILQ_FIRST(&pool->list); - PF_ACPY(&pool->counter, &pool->cur->addr.v.a.addr, - pca->af); + PF_ACPY(&pool->counter, &pool->cur->addr.v.a.addr, pca->af); PF_RULES_WUNLOCK(); break; #undef ERROUT DIOCCHANGEADDR_error: + if (newpa->kif) + pfi_kif_unref(newpa->kif); PF_RULES_WUNLOCK(); if (newpa != NULL) free(newpa, M_PFRULE);