summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authortuexen <tuexen@FreeBSD.org>2015-06-19 19:36:29 +0000
committertuexen <tuexen@FreeBSD.org>2015-06-19 19:36:29 +0000
commit7f7179926110b8d9d935bafd28b940572bd798f2 (patch)
treefb1b4710234d75ec26d75bb78558533bd3b40587 /usr.bin
parentb3c208462f0583e170d64dbf983bcdb2d1fe2508 (diff)
downloadFreeBSD-src-7f7179926110b8d9d935bafd28b940572bd798f2.zip
FreeBSD-src-7f7179926110b8d9d935bafd28b940572bd798f2.tar.gz
Don't leak sockets.
Reported by: Coverity CID: 1306785 MFC after: 3 days
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sockstat/sockstat.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index 1299f97..991b074 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -255,6 +255,26 @@ sockaddr(struct sockaddr_storage *sa, int af, void *addr, int port)
}
static void
+free_socket(struct sock *sock)
+{
+ struct addr *cur, *next;
+
+ cur = sock->laddr;
+ while (cur != NULL) {
+ next = cur->next;
+ free(cur);
+ cur = next;
+ }
+ cur = sock->faddr;
+ while (cur != NULL) {
+ next = cur->next;
+ free(cur);
+ cur = next;
+ }
+ free(sock);
+}
+
+static void
gather_sctp(void)
{
struct sock *sock;
@@ -366,14 +386,17 @@ gather_sctp(void)
while (offset < len) {
xstcb = (struct xsctp_tcb *)(void *)(buf + offset);
offset += sizeof(struct xsctp_tcb);
- if (no_stcb &&
- opt_l &&
- (!opt_L || !local_all_loopback) &&
- ((xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE) ||
- (xstcb->last == 1))) {
- hash = (int)((uintptr_t)sock->socket % HASHSIZE);
- sock->next = sockhash[hash];
- sockhash[hash] = sock;
+ if (no_stcb) {
+ if (opt_l &&
+ (!opt_L || !local_all_loopback) &&
+ ((xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE) ||
+ (xstcb->last == 1))) {
+ hash = (int)((uintptr_t)sock->socket % HASHSIZE);
+ sock->next = sockhash[hash];
+ sockhash[hash] = sock;
+ } else {
+ free_socket(sock);
+ }
}
if (xstcb->last == 1)
break;
@@ -476,11 +499,14 @@ gather_sctp(void)
prev_faddr->next = faddr;
prev_faddr = faddr;
}
- if (opt_c &&
- (!opt_L || !(local_all_loopback || foreign_all_loopback))) {
- hash = (int)((uintptr_t)sock->socket % HASHSIZE);
- sock->next = sockhash[hash];
- sockhash[hash] = sock;
+ if (opt_c) {
+ if (!opt_L || !(local_all_loopback || foreign_all_loopback)) {
+ hash = (int)((uintptr_t)sock->socket % HASHSIZE);
+ sock->next = sockhash[hash];
+ sockhash[hash] = sock;
+ } else {
+ free_socket(sock);
+ }
}
}
xinpcb = (struct xsctp_inpcb *)(void *)(buf + offset);
OpenPOWER on IntegriCloud