Don't leak sockets.

Reported by:	Coverity
CID:		1306785

MFC after:	3 days
This commit is contained in:
Michael Tuexen 2015-06-19 19:36:29 +00:00
parent a7647ec444
commit bedcf91d5c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=284604

View File

@ -254,6 +254,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)
{
@ -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);