From: Karel Zak Date: Thu, 29 Jan 2015 10:26:09 +0000 (+0100) Subject: su: fix mem leak in modify_environ() [coverity scan] X-Git-Tag: v2.26-rc2~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=101c5838aca7cc259f0d06626e993a21792c8232;p=thirdparty%2Futil-linux.git su: fix mem leak in modify_environ() [coverity scan] Signed-off-by: Karel Zak --- 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);