summaryrefslogtreecommitdiff
path: root/usr.sbin/syslogd/ttymsg.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2017-03-16 12:14:38 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2017-03-16 12:14:38 +0000
commit6a61ec6356cf128150b3c430de7b5efea137dd3e (patch)
treeb9f0acef533d1fc21cfcb810a5a78416dae09cea /usr.sbin/syslogd/ttymsg.c
parentb82375da07a1291952729cb545f2afc6d179e2ab (diff)
There was a file descripotor leak in the syslogd(8) ttymsg() error
path. Before returning early with an error, close the newly opened file descriptor. OK deraadt@
Diffstat (limited to 'usr.sbin/syslogd/ttymsg.c')
-rw-r--r--usr.sbin/syslogd/ttymsg.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.sbin/syslogd/ttymsg.c b/usr.sbin/syslogd/ttymsg.c
index e7c0738bb97..903bfc746fd 100644
--- a/usr.sbin/syslogd/ttymsg.c
+++ b/usr.sbin/syslogd/ttymsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttymsg.c,v 1.11 2016/08/16 18:41:57 tedu Exp $ */
+/* $OpenBSD: ttymsg.c,v 1.12 2017/03/16 12:14:37 bluhm Exp $ */
/* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */
/*
@@ -137,7 +137,7 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline)
if (tty_delayed >= TTYMAXDELAY) {
(void) snprintf(ebuf, sizeof(ebuf),
"%s: too many delayed writes", device);
- return (ebuf);
+ goto error;
}
logdebug("ttymsg delayed write\n");
if (iov != localiov) {
@@ -148,7 +148,7 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline)
if ((td = malloc(sizeof(*td))) == NULL) {
(void) snprintf(ebuf, sizeof(ebuf),
"%s: malloc: %s", device, strerror(errno));
- return (ebuf);
+ goto error;
}
td->td_length = 0;
if (left > MAXLINE)
@@ -176,9 +176,10 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline)
*/
if (errno == ENODEV || errno == EIO)
break;
- (void) close(fd);
(void) snprintf(ebuf, sizeof(ebuf),
"%s: %s", device, strerror(errno));
+ error:
+ (void) close(fd);
return (ebuf);
}