From 5d461ee23892389c8099d953b4d739d7a25c3acf Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Thu, 29 Feb 2024 09:46:06 -0500 Subject: [PATCH] Assert if soref() is called on an already-released socket. --- usrsctplib/user_socketvar.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/usrsctplib/user_socketvar.h b/usrsctplib/user_socketvar.h index e8eccc7fb..b46154ed8 100755 --- a/usrsctplib/user_socketvar.h +++ b/usrsctplib/user_socketvar.h @@ -403,6 +403,7 @@ void sofree(struct socket *so); #define soref(so) do { \ SOCK_LOCK_ASSERT(so); \ + KASSERT((so)->so_count >= 0, ("soref")); \ ++(so)->so_count; \ } while (0) @@ -410,8 +411,10 @@ void sofree(struct socket *so); ACCEPT_LOCK_ASSERT(); \ SOCK_LOCK_ASSERT(so); \ KASSERT((so)->so_count > 0, ("sorele")); \ - if (--(so)->so_count == 0) \ + if (--(so)->so_count == 0) { \ + (so)->so_count = -1; \ sofree(so); \ + } \ else { \ SOCK_UNLOCK(so); \ ACCEPT_UNLOCK(); \