summaryrefslogtreecommitdiff
path: root/lib/libproc
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2016-08-02 18:13:50 +0000
committerConrad Meyer <cem@FreeBSD.org>2016-08-02 18:13:50 +0000
commitce601a26765d5b38e176ea582256b8d8ecd33e2b (patch)
treeaf41f834fb8e357e150d77fc5b5973a3e98d63f7 /lib/libproc
parent0cd7a91aa7f5d7600071a257638748aeccc62f8a (diff)
downloadsrc-test-ce601a26765d5b38e176ea582256b8d8ecd33e2b.tar.gz
src-test-ce601a26765d5b38e176ea582256b8d8ecd33e2b.zip
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
Notes
Notes: svn path=/head/; revision=303669
Diffstat (limited to 'lib/libproc')
-rw-r--r--lib/libproc/proc_create.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libproc/proc_create.c b/lib/libproc/proc_create.c
index ad975b4c9979f..477fa6fd3003d 100644
--- a/lib/libproc/proc_create.c
+++ b/lib/libproc/proc_create.c
@@ -73,9 +73,9 @@ proc_init(pid_t pid, int flags, int status, struct proc_handle **pphdl)
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 status, struct proc_handle **pphdl)
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) {