PERFORCE change 43699 for review

Sam Leffler sam at FreeBSD.org
Tue Dec 9 15:10:40 PST 2003


http://perforce.freebsd.org/chv.cgi?CH=43699

Change 43699 by sam at sam_ebb on 2003/12/09 15:10:01

	o correct SOCK_ASSERT definition and renmae to SOCK_LOCK_ASSERT
	  for consistency
	o change sorele and sotryfree to assume(+assert) a held lock
	  and to zero the parameter to insure no use-after-free problems

Affected files ...

.. //depot/projects/netperf+sockets/sys/sys/socketvar.h#4 edit

Differences ...

==== //depot/projects/netperf+sockets/sys/sys/socketvar.h#4 (text+ko) ====

@@ -148,7 +148,7 @@
 #define	SOCK_LOCK(_so)			SOCKBUF_LOCK(&(_so)->so_rcv)
 #define	SOCK_OWNED(_so)			SOCKBUF_OWNED(&(_so)->so_rcv)
 #define	SOCK_UNLOCK(_so)		SOCKBUF_UNLOCK(&(_so)->so_rcv)
-#define	SOCK_ASSERT(_so)		SOCKBUF_ASSERT(&(_so)->so_rcv)
+#define	SOCK_LOCK_ASSERT(_so)		SOCKBUF_LOCK_ASSERT(&(_so)->so_rcv)
 
 /*
  * Socket state bits.
@@ -289,15 +289,24 @@
 } while (0)
 
 #define sorele(so) do {					\
+	SOCK_LOCK_ASSERT(so);				\
 	if ((so)->so_count <= 0)			\
 		panic("sorele");			\
 	if (--(so)->so_count == 0)			\
 		sofree(so);				\
+	else {						\
+		SOCK_UNLOCK(so);			\
+		so = NULL;				\
+	}						\
 } while (0)
 
 #define sotryfree(so) do {				\
+	SOCK_LOCK_ASSERT(so);				\
 	if ((so)->so_count == 0)			\
 		sofree(so);				\
+	else						\
+		SOCK_UNLOCK(so);			\
+	so = NULL;					\
 } while (0)
 
 #define	sorwakeup(so) do {				\


More information about the p4-projects mailing list