Skip to content

Commit

Permalink
Fix memory leak on error path
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Apr 2, 2022
1 parent 91b1993 commit 4a4ed5b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mx_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ int mx_proc_pid_stat(struct mx_proc_pid_stat **pps, pid_t pid)

pstat = *pps;
if (!pstat)
pstat = mx_calloc_forever(1, sizeof(*pstat));
*pps = pstat = mx_calloc_forever(1, sizeof(*pstat));

res = mx_proc_pid_stat_read(pstat, "/proc/%d/stat", pid);
if (res < 0)
return res;

*pps = pstat;
return 0;
}

Expand Down Expand Up @@ -370,9 +368,10 @@ int mx_proc_tree(struct mx_proc_tree **newtree)

pps = NULL;
res = mx_proc_pid_stat(&pps, pid);
if (res < 0)
if (res < 0) {
free(pps);
continue;

}
mx_proc_tree_add(pt, pps);
}
free(namelist);
Expand Down

0 comments on commit 4a4ed5b

Please sign in to comment.