From owner-svn-src-head@freebsd.org Tue Aug 2 18:13:51 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 3648ABAC200; Tue, 2 Aug 2016 18:13:51 +0000 (UTC) (envelope-from cem@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 059D11D4E; Tue, 2 Aug 2016 18:13:50 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u72IDoKA058572; Tue, 2 Aug 2016 18:13:50 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u72IDoDv058571; Tue, 2 Aug 2016 18:13:50 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201608021813.u72IDoDv058571@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Tue, 2 Aug 2016 18:13:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r303669 - head/lib/libproc 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.22 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: Tue, 02 Aug 2016 18:13:51 -0000 Author: cem Date: Tue Aug 2 18:13:50 2016 New Revision: 303669 URL: https://svnweb.freebsd.org/changeset/base/303669 Log: proc_init: Fix a few memory leaks of 'phdl' In the normal case and correct failure cases, the 'phdl' pointer is passed to callers to use or clean up as needed. However, some failure cases returned early, failing to export the phdl pointer. This was introduced in the restructuring of r303533. Reported by: Coverity CID: 1361070 Reviewed by: markj Sponsored by: EMC / Isilon Storage Division Modified: head/lib/libproc/proc_create.c Modified: head/lib/libproc/proc_create.c ============================================================================== --- head/lib/libproc/proc_create.c Tue Aug 2 17:23:45 2016 (r303668) +++ head/lib/libproc/proc_create.c Tue Aug 2 18:13:50 2016 (r303669) @@ -73,9 +73,9 @@ proc_init(pid_t pid, int flags, int stat struct proc_handle *phdl; int error, class, count, fd; - *pphdl = NULL; + error = ENOMEM; if ((phdl = malloc(sizeof(*phdl))) == NULL) - return (ENOMEM); + goto out; memset(phdl, 0, sizeof(*phdl)); phdl->pid = pid; @@ -83,17 +83,17 @@ proc_init(pid_t pid, int flags, int stat phdl->status = status; phdl->procstat = procstat_open_sysctl(); if (phdl->procstat == NULL) - return (ENOMEM); + goto out; /* Obtain a path to the executable. */ if ((kp = procstat_getprocs(phdl->procstat, KERN_PROC_PID, pid, &count)) == NULL) - return (ENOMEM); + goto out; error = procstat_getpathname(phdl->procstat, kp, phdl->execpath, sizeof(phdl->execpath)); procstat_freeprocs(phdl->procstat, kp); if (error != 0) - return (error); + goto out; /* Use it to determine the data model for the process. */ if ((fd = open(phdl->execpath, O_RDONLY)) < 0) {