From owner-svn-src-head@freebsd.org Sat Dec 31 10:01:26 2016 Return-Path: Delivered-To: svn-src-head@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 BB053C96072; Sat, 31 Dec 2016 10:01:26 +0000 (UTC) (envelope-from ngie@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 648B71AFA; Sat, 31 Dec 2016 10:01:26 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBVA1PiD012648; Sat, 31 Dec 2016 10:01:25 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBVA1P8Y012647; Sat, 31 Dec 2016 10:01:25 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201612311001.uBVA1P8Y012647@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Sat, 31 Dec 2016 10:01:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310894 - head/usr.sbin/bsnmpd/tools/bsnmptools 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.23 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: Sat, 31 Dec 2016 10:01:26 -0000 Author: ngie Date: Sat Dec 31 10:01:25 2016 New Revision: 310894 URL: https://svnweb.freebsd.org/changeset/base/310894 Log: snmp_pdu_free the right object at the right time in snmptool_walk r310892 was on the right track, but unfortunately it was resolving the problem incorrectly and accidentally leaking memory in the process. - Call snmp_pdu_free on req before calling snmp_pdu_create on it at the bottom of the outer while loop - Call snmp_pdu_free on resp after calling snmpwalk_nextpdu_create in the inner loop MFC after: 12 days X-MFC with: r310729, r310892 Reported by: valgrind Modified: head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Modified: head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c ============================================================================== --- head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Sat Dec 31 09:52:00 2016 (r310893) +++ head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Sat Dec 31 10:01:25 2016 (r310894) @@ -422,6 +422,7 @@ snmptool_get(struct snmp_toolinfo *snmpt snmp_pdu_create(&req, GET_PDUTYPE(snmptoolctx)); } + snmp_pdu_free(&req); snmp_pdu_free(&resp); return (0); @@ -507,6 +508,7 @@ snmptool_walk(struct snmp_toolinfo *snmp if (op == SNMP_PDU_GETBULK) snmpget_fix_getbulk(&req, GET_MAXREP(snmptoolctx), GET_NONREP(snmptoolctx)); + snmp_pdu_free(&resp); } /* Just in case our root was a leaf. */ @@ -517,6 +519,7 @@ snmptool_walk(struct snmp_toolinfo *snmp snmp_output_err_resp(snmptoolctx, &resp); else snmp_output_resp(snmptoolctx, &(resp), NULL); + snmp_pdu_free(&resp); } else warn("Snmp dialog"); } @@ -526,11 +529,13 @@ snmptool_walk(struct snmp_toolinfo *snmp break; } - snmp_pdu_free(&resp); - + snmp_pdu_free(&req); snmp_pdu_create(&req, op); } + snmp_pdu_free(&req); + snmp_pdu_free(&resp); + if (rc == 0) return (0); else