* Free the storage associated with a socket at the socket layer, tear down * locks, labels, etc. All protocol state is assumed already to have been * torn down (and possibly never set up) by the caller. */
| 457 | * torn down (and possibly never set up) by the caller. |
| 458 | */ |
| 459 | static void |
| 460 | sodealloc(struct socket *so) |
| 461 | { |
| 462 | |
| 463 | KASSERT(so->so_count == 0, ("sodealloc(): so_count %d", so->so_count)); |
| 464 | KASSERT(so->so_pcb == NULL, ("sodealloc(): so_pcb != NULL")); |
| 465 | |
| 466 | mtx_lock(&so_global_mtx); |
| 467 | so->so_gencnt = ++so_gencnt; |
| 468 | --numopensockets; /* Could be below, but faster here. */ |
| 469 | #ifdef VIMAGE |
| 470 | VNET_ASSERT(so->so_vnet != NULL, ("%s:%d so_vnet is NULL, so=%p", |
| 471 | __func__, __LINE__, so)); |
| 472 | so->so_vnet->vnet_sockcnt--; |
| 473 | #endif |
| 474 | mtx_unlock(&so_global_mtx); |
| 475 | #ifdef MAC |
| 476 | mac_socket_destroy(so); |
| 477 | #endif |
| 478 | hhook_run_socket(so, NULL, HHOOK_SOCKET_CLOSE); |
| 479 | |
| 480 | crfree(so->so_cred); |
| 481 | khelp_destroy_osd(&so->osd); |
| 482 | if (SOLISTENING(so)) { |
| 483 | if (so->sol_accept_filter != NULL) |
| 484 | accept_filt_setopt(so, NULL); |
| 485 | } else { |
| 486 | if (so->so_rcv.sb_hiwat) |
| 487 | (void)chgsbsize(so->so_cred->cr_uidinfo, |
| 488 | &so->so_rcv.sb_hiwat, 0, RLIM_INFINITY); |
| 489 | if (so->so_snd.sb_hiwat) |
| 490 | (void)chgsbsize(so->so_cred->cr_uidinfo, |
| 491 | &so->so_snd.sb_hiwat, 0, RLIM_INFINITY); |
| 492 | sx_destroy(&so->so_snd.sb_sx); |
| 493 | sx_destroy(&so->so_rcv.sb_sx); |
| 494 | SOCKBUF_LOCK_DESTROY(&so->so_snd); |
| 495 | SOCKBUF_LOCK_DESTROY(&so->so_rcv); |
| 496 | } |
| 497 | mtx_destroy(&so->so_lock); |
| 498 | uma_zfree(socket_zone, so); |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * socreate returns a socket with a ref count of 1. The socket should be |
no test coverage detected