summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorCan Erkin Acar <canacar@cvs.openbsd.org>2004-04-28 20:05:08 +0000
committerCan Erkin Acar <canacar@cvs.openbsd.org>2004-04-28 20:05:08 +0000
commit54b7c3c1749aae3a0dbfabadd6409c3040eb1a94 (patch)
treed5a57c8f5e348b86d84eea4da75b16a73d787ce5 /usr.sbin
parent2b4859cc0f047c8af23f6aef8b1158f4e2d1bf45 (diff)
Fix fd leaks.
Found by and ok deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/tcpdump/privsep_pcap.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.sbin/tcpdump/privsep_pcap.c b/usr.sbin/tcpdump/privsep_pcap.c
index 18747bcc776..fbaf701fd16 100644
--- a/usr.sbin/tcpdump/privsep_pcap.c
+++ b/usr.sbin/tcpdump/privsep_pcap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep_pcap.c,v 1.4 2004/04/14 09:14:19 otto Exp $ */
+/* $OpenBSD: privsep_pcap.c,v 1.5 2004/04/28 20:05:07 canacar Exp $ */
/*
* Copyright (c) 2004 Can Erkin Acar
@@ -350,8 +350,8 @@ swap_hdr(struct pcap_file_header *hp)
pcap_t *
priv_pcap_offline(const char *fname, char *errbuf)
{
- register pcap_t *p;
- register FILE *fp;
+ pcap_t *p;
+ FILE *fp = NULL;
struct pcap_file_header hdr;
int linklen, err;
@@ -382,6 +382,8 @@ priv_pcap_offline(const char *fname, char *errbuf)
fp = fdopen(p->fd, "r");
if (fp == NULL) {
+ close(p->fd);
+ p->fd = -1;
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", fname,
pcap_strerror(errno));
goto bad;
@@ -449,6 +451,8 @@ priv_pcap_offline(const char *fname, char *errbuf)
return (p);
bad:
+ if (fp != NULL && p->fd != -1)
+ fclose(fp);
free(p);
return (NULL);
}
@@ -498,6 +502,7 @@ priv_pcap_dump_open(pcap_t *p, char *fname)
}
f = fdopen(fd, "w");
if (f == NULL) {
+ close(fd);
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
fname, pcap_strerror(errno));
return (NULL);