+/* note: rip_unlock is called from different protos instead of the generic socket_unlock,
+ * it will handle the socket dealloc on last reference
+ * */
+int
+rip_unlock(struct socket *so, int refcount, int debug)
+{
+ int lr_saved;
+ struct inpcb *inp = sotoinpcb(so);
+
+ if (debug == 0)
+ lr_saved = (unsigned int) __builtin_return_address(0);
+ else lr_saved = debug;
+
+ if (refcount) {
+ if (so->so_usecount <= 0)
+ panic("rip_unlock: bad refoucnt so=%x val=%x\n", so, so->so_usecount);
+ so->so_usecount--;
+ if (so->so_usecount == 0 && (inp->inp_wantcnt == WNT_STOPUSING)) {
+ /* cleanup after last reference */
+ lck_mtx_unlock(so->so_proto->pr_domain->dom_mtx);
+ lck_rw_lock_exclusive(ripcbinfo.mtx);
+ in_pcbdispose(inp);
+ lck_rw_done(ripcbinfo.mtx);
+ return(0);
+ }
+ }
+ so->unlock_lr[so->next_unlock_lr] = (u_int *)lr_saved;
+ so->next_unlock_lr = (so->next_unlock_lr+1) % SO_LCKDBG_MAX;
+ lck_mtx_unlock(so->so_proto->pr_domain->dom_mtx);
+ return(0);
+}
+