diff --git a/fw/sock_srv.c b/fw/sock_srv.c index 6eb3a33a1d..dfbd806dc6 100644 --- a/fw/sock_srv.c +++ b/fw/sock_srv.c @@ -504,8 +504,9 @@ tfw_sock_srv_disconnect(TfwConn *conn) * restored already. If the connection is closed already, then * check its stop bit. */ - if (atomic_read(&conn->refcnt) != TFW_CONN_DEATHCNT) { + if (__tfw_connection_get_if_live(conn)) { TfwServer *srv = (TfwServer *)conn->peer; + int r = 0; /* * We set TFW_CFG_B_DEL flag when we gracefully @@ -521,10 +522,12 @@ tfw_sock_srv_disconnect(TfwConn *conn) */ if (test_bit(TFW_CFG_B_DEL, &srv->flags)) { tfw_connection_abort(conn); - return 0; + } else { + r = tfw_connection_close(conn, true); } - return tfw_connection_close(conn, true); + tfw_connection_put(conn); + return r; } /* * If stop flag is set, we can exit. Otherwise, continue waiting