]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix memory leak in zfs_setprocinit code
authorPaul Dagnelie <pcd@delphix.com>
Fri, 17 Nov 2023 21:21:04 +0000 (13:21 -0800)
committerGitHub <noreply@github.com>
Fri, 17 Nov 2023 21:21:04 +0000 (13:21 -0800)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rich Ercolani <rincebrain@gmail.com>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #15508

lib/libzutil/os/linux/zutil_setproctitle.c

index 4a6d12cf70cf61a9d9b747d82dd6ae33aec1b204..5961527ebc2c0f16dee5e99721a8d764bdb12c6c 100644 (file)
@@ -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[])
 {
@@ -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], '=');
@@ -142,6 +118,7 @@ spt_copyenv(int envc, char *envp[])
                *eq = '=';
 
                if (error) {
+                       clearenv();
                        environ = envp;
                        free(envcopy);
                        return (error);