summaryrefslogtreecommitdiff
path: root/loginrec.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2011-01-02 21:43:59 +1100
committerDamien Miller <djm@mindrot.org>2011-01-02 21:43:59 +1100
commit4a06f9271fe5341c942232015add391cee366b68 (patch)
tree12382e6c6a226dad9553552343c92e03096d2da3 /loginrec.c
parent928362dc0312f5d258da0a98ab48f35bfaa368f1 (diff)
- (djm) [loginrec.c] Fix some fd leaks on error paths. ok dtucker
Diffstat (limited to 'loginrec.c')
-rw-r--r--loginrec.c9
1 files changed, 8 insertions, 1 deletions
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)
873 pos = (off_t)tty * sizeof(struct utmp); 873 pos = (off_t)tty * sizeof(struct utmp);
874 if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { 874 if ((ret = lseek(fd, pos, SEEK_SET)) == -1) {
875 logit("%s: lseek: %s", __func__, strerror(errno)); 875 logit("%s: lseek: %s", __func__, strerror(errno));
876 close(fd);
876 return (0); 877 return (0);
877 } 878 }
878 if (ret != pos) { 879 if (ret != pos) {
879 logit("%s: Couldn't seek to tty %d slot in %s", 880 logit("%s: Couldn't seek to tty %d slot in %s",
880 __func__, tty, UTMP_FILE); 881 __func__, tty, UTMP_FILE);
882 close(fd);
881 return (0); 883 return (0);
882 } 884 }
883 /* 885 /*
@@ -893,16 +895,20 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut)
893 895
894 if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { 896 if ((ret = lseek(fd, pos, SEEK_SET)) == -1) {
895 logit("%s: lseek: %s", __func__, strerror(errno)); 897 logit("%s: lseek: %s", __func__, strerror(errno));
898 close(fd);
896 return (0); 899 return (0);
897 } 900 }
898 if (ret != pos) { 901 if (ret != pos) {
899 logit("%s: Couldn't seek to tty %d slot in %s", 902 logit("%s: Couldn't seek to tty %d slot in %s",
900 __func__, tty, UTMP_FILE); 903 __func__, tty, UTMP_FILE);
904 close(fd);
901 return (0); 905 return (0);
902 } 906 }
903 if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) { 907 if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) {
904 logit("%s: error writing %s: %s", __func__, 908 logit("%s: error writing %s: %s", __func__,
905 UTMP_FILE, strerror(errno)); 909 UTMP_FILE, strerror(errno));
910 close(fd);
911 return (0);
906 } 912 }
907 913
908 close(fd); 914 close(fd);
@@ -1206,7 +1212,7 @@ wtmp_get_entry(struct logininfo *li)
1206 close (fd); 1212 close (fd);
1207 return (0); 1213 return (0);
1208 } 1214 }
1209 if ( wtmp_islogin(li, &ut) ) { 1215 if (wtmp_islogin(li, &ut) ) {
1210 found = 1; 1216 found = 1;
1211 /* 1217 /*
1212 * We've already checked for a time in struct 1218 * We've already checked for a time in struct
@@ -1502,6 +1508,7 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
1502 if (lseek(*fd, offset, SEEK_SET) != offset) { 1508 if (lseek(*fd, offset, SEEK_SET) != offset) {
1503 logit("%s: %s->lseek(): %s", __func__, 1509 logit("%s: %s->lseek(): %s", __func__,
1504 lastlog_file, strerror(errno)); 1510 lastlog_file, strerror(errno));
1511 close(*fd);
1505 return (0); 1512 return (0);
1506 } 1513 }
1507 } 1514 }