Fix memory leak in zfs_setprocinit code

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rich Ercolani <rincebrain@gmail.com>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #15508
This commit is contained in:
Paul Dagnelie 2023-11-17 13:21:04 -08:00 committed by GitHub
parent 03e9caaec0
commit 6c6fae6fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,25 +82,6 @@ spt_min(size_t a, size_t b)
return ((a < b) ? a : 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 static int
spt_copyenv(int envc, char *envp[]) spt_copyenv(int envc, char *envp[])
{ {
@ -124,12 +105,7 @@ spt_copyenv(int envc, char *envp[])
return (errno); return (errno);
memcpy(envcopy, envp, envsize); memcpy(envcopy, envp, envsize);
error = spt_clearenv(); environ = NULL;
if (error) {
environ = envp;
free(envcopy);
return (error);
}
for (i = 0; envcopy[i]; i++) { for (i = 0; envcopy[i]; i++) {
eq = strchr(envcopy[i], '='); eq = strchr(envcopy[i], '=');
@ -142,6 +118,7 @@ spt_copyenv(int envc, char *envp[])
*eq = '='; *eq = '=';
if (error) { if (error) {
clearenv();
environ = envp; environ = envp;
free(envcopy); free(envcopy);
return (error); return (error);