[master] 5dc880134 miniobj: Add a FINI_OBJ() macro

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Sep 20 12:40:07 UTC 2021


commit 5dc8801348904cbe7146fa92113b3c3fb7ac7097
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Sep 6 07:42:17 2021 +0200

    miniobj: Add a FINI_OBJ() macro
    
    It operates on a pointer like FREE_OBJ() and clears it.

diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index f3a9619c0..f0013de1b 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -425,8 +425,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
 	CAST_OBJ_NOTNULL(xp, (const void*)wp->priv2, TRANSPORT_MAGIC);
 	AN(wp->priv2);
 	assert(WS_Reservation(sp->ws) == wp);
-	wp->magic = 0;
-	wp = NULL;
+	FINI_OBJ(wp);
 
 	/* The WS was reserved in SES_Wait() */
 	WS_Release(sp->ws, 0);
diff --git a/bin/varnishd/hpack/vhp_table.c b/bin/varnishd/hpack/vhp_table.c
index 4415f47b8..33798f39b 100644
--- a/bin/varnishd/hpack/vhp_table.c
+++ b/bin/varnishd/hpack/vhp_table.c
@@ -122,7 +122,7 @@ vht_trim(struct vht_table *tbl, ssize_t max)
 			assert(e->offset == u);
 			u += ENTRYLEN(e);
 			v++;
-			e->magic = 0;
+			FINI_OBJ(e);
 		} else {
 			/* Fixup offset */
 			assert(e->offset >= u);
@@ -257,7 +257,7 @@ VHT_NewEntry_Indexed(struct vht_table *tbl, unsigned idx)
 	assert(e->offset == 0);
 	lname = e->namelen;
 	lentry = ENTRYLEN(e);
-	e->magic = 0;
+	FINI_OBJ(e);
 	memmove(TBLENTRY(tbl, 1), TBLENTRY(tbl, 0), (tbl->n - 1) * sizeof *e);
 	tbl->n--;
 
@@ -462,7 +462,7 @@ VHT_Init(struct vht_table *tbl, size_t protomax)
 	INIT_OBJ(tbl, VHT_TABLE_MAGIC);
 	r = VHT_SetProtoMax(tbl, protomax);
 	if (r) {
-		tbl->magic = 0;
+		FINI_OBJ(tbl);
 		return (r);
 	}
 	tbl->maxsize = tbl->protomax;
diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c
index 6bc062ee1..6e67b55c5 100644
--- a/bin/varnishd/http2/cache_http2_hpack.c
+++ b/bin/varnishd/http2/cache_http2_hpack.c
@@ -216,7 +216,7 @@ h2h_decode_fini(const struct h2_sess *h2)
 		ret = H2CE_COMPRESSION_ERROR;
 	} else
 		ret = d->error;
-	d->magic = 0;
+	FINI_OBJ(d);
 	return (ret);
 }
 
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index bcf00c75b..c5c335848 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -252,18 +252,21 @@ sml_slim(struct worker *wrk, struct objcore *oc)
 static void v_matchproto_(objfree_f)
 sml_objfree(struct worker *wrk, struct objcore *oc)
 {
+	struct storage *st;
 	struct object *o;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	sml_slim(wrk, oc);
 	CAST_OBJ_NOTNULL(o, oc->stobj->priv, OBJECT_MAGIC);
-	o->magic = 0;
+	st = o->objstore;
+	CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
+	FINI_OBJ(o);
 
 	if (oc->boc == NULL && oc->stobj->stevedore->lru != NULL)
 		LRU_Remove(oc);
 
-	sml_stv_free(oc->stobj->stevedore, o->objstore);
+	sml_stv_free(oc->stobj->stevedore, st);
 
 	memset(oc->stobj, 0, sizeof oc->stobj);
 
diff --git a/include/miniobj.h b/include/miniobj.h
index 8da6ef42e..8babaa251 100644
--- a/include/miniobj.h
+++ b/include/miniobj.h
@@ -17,6 +17,12 @@
 		(to)->magic = (type_magic);				\
 	} while (0)
 
+#define FINI_OBJ(to)							\
+	do {								\
+		ZERO_OBJ(&(to)->magic, sizeof (to)->magic);		\
+		to = NULL;						\
+	} while (0)
+
 #define ALLOC_OBJ(to, type_magic)					\
 	do {								\
 		(to) = calloc(1, sizeof *(to));				\
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index ab3544899..aacdbbb23 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -337,8 +337,8 @@ VEV_Stop(struct vev_root *evb, struct vev *e)
 		es->happened = 0;
 	}
 
-	e->magic = 0;
 	e->__vevb = NULL;
+	FINI_OBJ(e);
 }
 
 /*--------------------------------------------------------------------*/


More information about the varnish-commit mailing list