From 4a06f9271fe5341c942232015add391cee366b68 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Sun, 2 Jan 2011 21:43:59 +1100 Subject: - (djm) [loginrec.c] Fix some fd leaks on error paths. ok dtucker --- loginrec.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'loginrec.c') diff --git a/loginrec.c b/loginrec.c index cccaa47ae..587d55f7d 100644 --- a/loginrec.c +++ b/loginrec.c @@ -873,11 +873,13 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut) pos = (off_t)tty * sizeof(struct utmp); if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { logit("%s: lseek: %s", __func__, strerror(errno)); + close(fd); return (0); } if (ret != pos) { logit("%s: Couldn't seek to tty %d slot in %s", __func__, tty, UTMP_FILE); + close(fd); return (0); } /* @@ -893,16 +895,20 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut) if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { logit("%s: lseek: %s", __func__, strerror(errno)); + close(fd); return (0); } if (ret != pos) { logit("%s: Couldn't seek to tty %d slot in %s", __func__, tty, UTMP_FILE); + close(fd); return (0); } if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) { logit("%s: error writing %s: %s", __func__, UTMP_FILE, strerror(errno)); + close(fd); + return (0); } close(fd); @@ -1206,7 +1212,7 @@ wtmp_get_entry(struct logininfo *li) close (fd); return (0); } - if ( wtmp_islogin(li, &ut) ) { + if (wtmp_islogin(li, &ut) ) { found = 1; /* * We've already checked for a time in struct @@ -1502,6 +1508,7 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode) if (lseek(*fd, offset, SEEK_SET) != offset) { logit("%s: %s->lseek(): %s", __func__, lastlog_file, strerror(errno)); + close(*fd); return (0); } } -- cgit v1.2.3