From: Karel Zak Date: Thu, 29 Jan 2015 10:25:07 +0000 (+0100) Subject: login: fix mem leak in init_environ() [coverity scan] X-Git-Tag: v2.26-rc2~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86cf1ff42aa89fbf10afddb363df370575649806;p=thirdparty%2Futil-linux.git login: fix mem leak in init_environ() [coverity scan] Signed-off-by: Karel Zak --- diff --git a/login-utils/login.c b/login-utils/login.c index 8772068c7e..8d4b01b10e 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -1038,12 +1038,13 @@ static void fork_session(struct login_context *cxt) static void init_environ(struct login_context *cxt) { struct passwd *pwd = cxt->pwd; - char *termenv = NULL, **env; + char *termenv, **env; char tmp[PATH_MAX]; int len, i; termenv = getenv("TERM"); - termenv = termenv ? xstrdup(termenv) : "dumb"; + if (termenv) + termenv = xstrdup(termenv); /* destroy environment unless user has requested preservation (-p) */ if (!cxt->keep_env) { @@ -1054,7 +1055,8 @@ static void init_environ(struct login_context *cxt) setenv("HOME", pwd->pw_dir, 0); /* legal to override */ setenv("USER", pwd->pw_name, 1); setenv("SHELL", pwd->pw_shell, 1); - setenv("TERM", termenv, 1); + setenv("TERM", termenv ? termenv : "dumb", 1); + free(termenv); if (pwd->pw_uid) logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH);