From: Karel Zak Date: Mon, 28 Jan 2008 13:02:35 +0000 (+0100) Subject: login: fix a small memory leak and remove unnecessary zeroing X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30568eec590764ab5cdd263a054df2c9fa38286f;p=util-linux login: fix a small memory leak and remove unnecessary zeroing This patch fix a small memory leak (rh#251539) and also remove unnecessary pam_set_item(). We needn't to zeroing PAM_USER when the value is already NULL, it doesn't make sense. Addresses-Red-Hat-Bugzilla: #251539 Signed-off-by: Karel Zak --- diff --git a/login-utils/login.c b/login-utils/login.c index d40381d4..0e6db2b5 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -579,6 +579,12 @@ main(int argc, char **argv) fprintf(stderr,"\033(K"); #endif + if (username) { + /* we need't the original username. We have to follow PAM. */ + free(username); + username = NULL; + } + /* if fflag == 1, then the user has already been authenticated */ if (fflag && (getuid() == 0)) passwd_req = 0; @@ -590,8 +596,6 @@ main(int argc, char **argv) /* if we didn't get a user on the command line, set it to NULL */ pam_get_item(pamh, PAM_USER, (const void **) &username); - if (!username) - pam_set_item(pamh, PAM_USER, NULL); /* there may be better ways to deal with some of these conditions, but at least this way I don't think we'll