From owner-svn-src-all@freebsd.org Wed May 11 10:04:33 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7C9E8B34B7D; Wed, 11 May 2016 10:04:33 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4E6191489; Wed, 11 May 2016 10:04:33 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4BA4W2Q008494; Wed, 11 May 2016 10:04:32 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4BA4WKD008493; Wed, 11 May 2016 10:04:32 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201605111004.u4BA4WKD008493@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Wed, 11 May 2016 10:04:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299420 - head/sys/netpfil/ipfw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2016 10:04:33 -0000 Author: ae Date: Wed May 11 10:04:32 2016 New Revision: 299420 URL: https://svnweb.freebsd.org/changeset/base/299420 Log: Fix memory leak possible in error case. Use free_rule() instead of free(), it will also release memory allocated for rule counters. Obtained from: Yandex LLC Sponsored by: Yandex LLC Modified: head/sys/netpfil/ipfw/ip_fw_sockopt.c Modified: head/sys/netpfil/ipfw/ip_fw_sockopt.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_sockopt.c Wed May 11 10:03:13 2016 (r299419) +++ head/sys/netpfil/ipfw/ip_fw_sockopt.c Wed May 11 10:04:32 2016 (r299420) @@ -2751,7 +2751,7 @@ add_rules(struct ip_fw_chain *chain, ip_ if ((error = commit_rules(chain, cbuf, rtlv->count)) != 0) { /* Free allocate krules */ for (i = 0, ci = cbuf; i < rtlv->count; i++, ci++) - free(ci->krule, M_IPFW); + free_rule(ci->krule); } if (cbuf != NULL && cbuf != &rci) @@ -3574,7 +3574,9 @@ ipfw_ctl(struct sockopt *sopt) ci.krule = krule; import_rule0(&ci); error = commit_rules(chain, &ci, 1); - if (!error && sopt->sopt_dir == SOPT_GET) { + if (error != 0) + free_rule(ci.krule); + else if (sopt->sopt_dir == SOPT_GET) { if (is7) { error = convert_rule_to_7(rule); size = RULESIZE7(rule);