summaryrefslogtreecommitdiffstats
path: root/usr.bin/last/last.c
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1996-10-28 07:47:34 +0000
committerjoerg <joerg@FreeBSD.org>1996-10-28 07:47:34 +0000
commit2b0d357ce4408ba1b7b5b5a12289ff8d6a240be8 (patch)
tree9512b6a560cea3099302ee8e659e1af151e6772c /usr.bin/last/last.c
parent89ffae8fb207c772c825863b2c2754e09a59c212 (diff)
downloadFreeBSD-src-2b0d357ce4408ba1b7b5b5a12289ff8d6a240be8.zip
FreeBSD-src-2b0d357ce4408ba1b7b5b5a12289ff8d6a240be8.tar.gz
Don't dereference a free()ed pointer.
Closes PR bin/1909: 'last' coredumps if MALLOC_OPTIONS...
Diffstat (limited to 'usr.bin/last/last.c')
-rw-r--r--usr.bin/last/last.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c
index 89dcef8..25a7627 100644
--- a/usr.bin/last/last.c
+++ b/usr.bin/last/last.c
@@ -162,7 +162,7 @@ void
wtmp()
{
struct utmp *bp; /* current structure */
- struct ttytab *tt; /* ttylist entry */
+ struct ttytab *tt, *ttx; /* ttylist entry */
struct stat stb; /* stat of file for size */
long bl, delta; /* time difference */
int bytes, wfd;
@@ -191,9 +191,11 @@ wtmp()
*/
if (bp->ut_line[0] == '~' && !bp->ut_line[1]) {
/* everybody just logged out */
- for (tt = ttylist.lh_first; tt; tt = tt->list.le_next) {
+ for (tt = ttylist.lh_first; tt;) {
LIST_REMOVE(tt, list);
- free(tt);
+ ttx = tt;
+ tt = tt->list.le_next;
+ free(ttx);
}
currentout = -bp->ut_time;
crmsg = strncmp(bp->ut_name, "shutdown",
OpenPOWER on IntegriCloud