summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2015-01-29 11:26:09 +0100
committerKarel Zak2015-01-29 11:26:09 +0100
commit101c5838aca7cc259f0d06626e993a21792c8232 (patch)
tree8b8e3a115ec7198317d127b24676fb0e320a60f9
parentlogin: fix mem leak in init_environ() [coverity scan] (diff)
downloadkernel-qcow2-util-linux-101c5838aca7cc259f0d06626e993a21792c8232.tar.gz
kernel-qcow2-util-linux-101c5838aca7cc259f0d06626e993a21792c8232.tar.xz
kernel-qcow2-util-linux-101c5838aca7cc259f0d06626e993a21792c8232.zip
su: fix mem leak in modify_environ() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--login-utils/su-common.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index 57038ce37..2d4707330 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -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);