Skip to content

Commit

Permalink
Fix memory leak in zfs_setprocinit code
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Rich Ercolani <[email protected]>
Signed-off-by: Paul Dagnelie <[email protected]>
Closes openzfs#15508
  • Loading branch information
pcd1193182 authored Nov 17, 2023
1 parent 03e9caa commit 6c6fae6
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions lib/libzutil/os/linux/zutil_setproctitle.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,6 @@ spt_min(size_t a, size_t b)
return ((a < b) ? a : b);
}

/*
* For discussion on the portability of the various methods, see
* https://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html
*/
static int
spt_clearenv(void)
{
char **tmp;

tmp = malloc(sizeof (*tmp));
if (tmp == NULL)
return (errno);

tmp[0] = NULL;
environ = tmp;

return (0);
}

static int
spt_copyenv(int envc, char *envp[])
{
Expand All @@ -124,12 +105,7 @@ spt_copyenv(int envc, char *envp[])
return (errno);
memcpy(envcopy, envp, envsize);

error = spt_clearenv();
if (error) {
environ = envp;
free(envcopy);
return (error);
}
environ = NULL;

for (i = 0; envcopy[i]; i++) {
eq = strchr(envcopy[i], '=');
Expand All @@ -142,6 +118,7 @@ spt_copyenv(int envc, char *envp[])
*eq = '=';

if (error) {
clearenv();
environ = envp;
free(envcopy);
return (error);
Expand Down

0 comments on commit 6c6fae6

Please sign in to comment.