]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
su: fix mem leak in modify_environ() [coverity scan]
authorKarel Zak <kzak@redhat.com>
Thu, 29 Jan 2015 10:26:09 +0000 (11:26 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Jan 2015 10:26:09 +0000 (11:26 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/su-common.c

index 57038ce37a95ec1c34a29d8528f53f1f29cd714c..2d470733063d79149c2527d45cf89973cdc1166e 100644 (file)
@@ -533,13 +533,15 @@ modify_environment (const struct passwd *pw, const char *shell)
     {
       /* Leave TERM unchanged.  Set HOME, SHELL, USER, LOGNAME, PATH.
          Unset all other environment variables.  */
-      char const *term = getenv ("TERM");
+      char *term = getenv ("TERM");
       if (term)
        term = xstrdup (term);
       environ = xmalloc ((6 + !!term) * sizeof (char *));
       environ[0] = NULL;
-      if (term)
+      if (term) {
        xsetenv ("TERM", term, 1);
+       free(term);
+      }
       xsetenv ("HOME", pw->pw_dir, 1);
       if (shell)
        xsetenv ("SHELL", shell, 1);