[master] f5d952c6a Consistently lock 'vsc' variable even if not necessary (for Coverity)

Poul-Henning Kamp phk at FreeBSD.org
Wed Dec 6 10:12:08 UTC 2023


commit f5d952c6a3e1a692d913f1ebf0332e18f49ccdf3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Dec 6 10:10:27 2023 +0000

    Consistently lock 'vsc' variable even if not necessary (for Coverity)

diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c
index 2f5390f09..9a98fe700 100644
--- a/vmod/vmod_debug.c
+++ b/vmod/vmod_debug.c
@@ -714,8 +714,12 @@ event_discard(VRT_CTX, void *priv)
 	 * of this VMOD, so we should only carry out cleanup on the
 	 * last discard event.
 	 */
-	if (vsc)
+	PTOK(pthread_mutex_lock(&vsc_mtx));
+	if (vsc != NULL) {
 		VSC_debug_Destroy(&vsc_seg);
+		vsc = NULL;
+	}
+	PTOK(pthread_mutex_unlock(&vsc_mtx));
 
 	return (0);
 }
@@ -772,8 +776,10 @@ VCL_VOID
 xyzzy_vsc_count(VRT_CTX, VCL_INT cnt)
 {
 	(void)ctx;
+	PTOK(pthread_mutex_lock(&vsc_mtx));
 	AN(vsc);
 	vsc->count += cnt;
+	PTOK(pthread_mutex_unlock(&vsc_mtx));
 }
 
 VCL_VOID


More information about the varnish-commit mailing list