login: fix leak, improve strtok usage

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-02-06 12:51:55 +01:00
parent 23925360bb
commit 34bb8eea90
1 changed files with 6 additions and 2 deletions

View File

@ -217,7 +217,7 @@ static const char *get_thishost(struct login_context *cxt, const char **domain)
*/
static void motd(void)
{
char *motdlist, *motdfile, *cp;
char *motdlist, *motdfile;
const char *mb;
mb = getlogindefs_str("MOTD_FILE", _PATH_MOTDFILE);
@ -226,7 +226,9 @@ static void motd(void)
motdlist = xstrdup(mb);
for (cp = motdlist; (motdfile = strtok(cp, ":")); cp = NULL) {
for (motdfile = strtok(motdlist, ":"); motdfile;
motdfile = strtok(NULL, ":")) {
struct stat st;
int fd;
@ -239,6 +241,8 @@ static void motd(void)
sendfile(fileno(stdout), fd, NULL, st.st_size);
close(fd);
}
free(motdlist);
}
/*