From 101c5838aca7cc259f0d06626e993a21792c8232 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 29 Jan 2015 11:26:09 +0100 Subject: [PATCH] su: fix mem leak in modify_environ() [coverity scan] Signed-off-by: Karel Zak --- login-utils/su-common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 57038ce37a..2d47073306 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); -- 2.47.2