[master] 328540c6c tree-wide: add missing magic checks

Poul-Henning Kamp phk at FreeBSD.org
Tue Aug 17 06:16:08 UTC 2021


commit 328540c6ca58b8009d739ea542442a9d24372ce2
Author: Asad Sajjad Ahmed <asadsa at varnish-software.com>
Date:   Tue Aug 10 20:35:58 2021 +0200

    tree-wide: add missing magic checks
    
    Signed-off-by: Asad Sajjad Ahmed <asadsa at varnish-software.com>

diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index f56a9fac6..5fa8b1b7e 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -102,6 +102,8 @@ static const unsigned char vbp_proxy_local[] = {
 static void
 vbp_delete(struct vbp_target *vt)
 {
+	CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
+
 #define DN(x)	/**/
 	VRT_BACKEND_PROBE_HANDLE();
 #undef DN
diff --git a/bin/varnishd/cache/cache_conn_pool.c b/bin/varnishd/cache/cache_conn_pool.c
index c8d39e21d..4f4b1b210 100644
--- a/bin/varnishd/cache/cache_conn_pool.c
+++ b/bin/varnishd/cache/cache_conn_pool.c
@@ -156,6 +156,7 @@ vcp_handle(struct waited *w, enum wait_event ev, vtim_real now)
 	struct pfd *pfd;
 	struct conn_pool *cp;
 
+	CHECK_OBJ_NOTNULL(w, WAITED_MAGIC);
 	CAST_OBJ_NOTNULL(pfd, w->priv1, PFD_MAGIC);
 	(void)ev;
 	(void)now;
@@ -730,6 +731,7 @@ VCP_Ref(const struct vrt_endpoint *vep, const char *ident)
 	cp->refcnt = 1;
 	cp->holddown = 0;
 	cp->endpoint = VRT_Endpoint_Clone(vep);
+	CHECK_OBJ_NOTNULL(cp->endpoint, VRT_ENDPOINT_MAGIC);
 	memcpy(cp->ident, digest, sizeof cp->ident);
 	if (vep->uds_path != NULL)
 		cp->methods = &vus_methods;
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 082e32631..466e096a4 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -296,10 +296,8 @@ ved_vdp_esi_fini(struct vdp_ctx *vdc, void **priv)
 	struct ecx *ecx;
 
 	(void)vdc;
-	AN(priv);
-	CAST_OBJ_NOTNULL(ecx, *priv, ECX_MAGIC);
+	TAKE_OBJ_NOTNULL(ecx, priv, ECX_MAGIC);
 	FREE_OBJ(ecx);
-	*priv = NULL;
 	return (0);
 }
 
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 90c7a7ca8..1af3a3793 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -162,9 +162,9 @@ HSH_Cleanup(const struct worker *wrk)
 		ObjDestroy(wrk, &wrk->wpriv->nobjcore);
 
 	if (wrk->wpriv->nobjhead != NULL) {
+		CHECK_OBJ(wrk->wpriv->nobjhead, OBJHEAD_MAGIC);
 		Lck_Delete(&wrk->wpriv->nobjhead->mtx);
 		FREE_OBJ(wrk->wpriv->nobjhead);
-		wrk->wpriv->nobjhead = NULL;
 		wrk->stats->n_objecthead--;
 	}
 	if (wrk->wpriv->nhashpriv != NULL) {
@@ -177,6 +177,8 @@ HSH_Cleanup(const struct worker *wrk)
 void
 HSH_DeleteObjHead(const struct worker *wrk, struct objhead *oh)
 {
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 
 	AZ(oh->refcnt);
 	assert(VTAILQ_EMPTY(&oh->objcs));
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index b6d69bd61..eec6cfa65 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -115,8 +115,8 @@ mpl_guard(void *priv)
 
 		if (mi != NULL && (mpl->n_pool > mpl->param->max_pool ||
 		    mi->size < *mpl->cur_size)) {
+			CHECK_OBJ(mi, MEMITEM_MAGIC);
 			FREE_OBJ(mi);
-			mi = NULL;
 		}
 
 		if (mi == NULL && mpl->n_pool < mpl->param->min_pool)
@@ -160,8 +160,8 @@ mpl_guard(void *priv)
 				}
 				if (mi == NULL)
 					break;
+				CHECK_OBJ(mi, MEMITEM_MAGIC);
 				FREE_OBJ(mi);
-				mi = NULL;
 			}
 			VSC_mempool_Destroy(&mpl->vsc_seg);
 			Lck_Unlock(&mpl->mtx);
@@ -172,7 +172,7 @@ mpl_guard(void *priv)
 
 		if (mpl->n_pool < mpl->param->min_pool &&
 		    mi != NULL && mi->size >= *mpl->cur_size) {
-			CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
+			CHECK_OBJ(mi, MEMITEM_MAGIC);
 			mpl->vsc->pool = ++mpl->n_pool;
 			mi->touched = mpl->t_now;
 			VTAILQ_INSERT_HEAD(&mpl->list, mi, list);
@@ -215,8 +215,8 @@ mpl_guard(void *priv)
 		Lck_Unlock(&mpl->mtx);
 
 		if (mi != NULL) {
+			CHECK_OBJ(mi, MEMITEM_MAGIC);
 			FREE_OBJ(mi);
-			mi = NULL;
 		}
 	}
 	return (NULL);
@@ -288,7 +288,7 @@ MPL_Get(struct mempool *mpl, unsigned *size)
 			break;
 		}
 		mpl->vsc->pool = --mpl->n_pool;
-		CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
+		CHECK_OBJ(mi, MEMITEM_MAGIC);
 		VTAILQ_REMOVE(&mpl->list, mi, list);
 		if (mi->size < *mpl->cur_size) {
 			mpl->vsc->toosmall++;
@@ -305,7 +305,7 @@ MPL_Get(struct mempool *mpl, unsigned *size)
 		mi = mpl_alloc(mpl);
 	*size = mi->size - sizeof *mi;
 
-	CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
+	CHECK_OBJ(mi, MEMITEM_MAGIC);
 	/* Throw away sizeof info for FlexeLint: */
 	return ((void *)(uintptr_t)(mi + 1));
 }
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index 1bab08f36..6c77d5840 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -200,7 +200,7 @@ pool_poolherder(void *priv)
 				DO_DEBUG(DBG_DROP_POOLS)) {
 			Lck_Lock(&pool_mtx);
 			pp = VTAILQ_FIRST(&pools);
-			AN(pp);
+			CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 			VTAILQ_REMOVE(&pools, pp, list);
 			VTAILQ_INSERT_TAIL(&pools, pp, list);
 			if (!pp->die)
@@ -218,6 +218,8 @@ pool_poolherder(void *priv)
 		ppx = NULL;
 		Lck_Lock(&pool_mtx);
 		VTAILQ_FOREACH(pp, &pools, list) {
+			CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
+
 			if (pp->die && pp->nthr == 0)
 				ppx = pp;
 			u += pp->lqueue;
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index d70e9543f..0efded131 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -517,9 +517,7 @@ VCL_Close(struct vcl **vclp)
 {
 	struct vcl *vcl;
 
-	CHECK_OBJ_NOTNULL(*vclp, VCL_MAGIC);
-	vcl = *vclp;
-	*vclp = NULL;
+	TAKE_OBJ_NOTNULL(vcl, vclp, VCL_MAGIC);
 	assert(VTAILQ_EMPTY(&vcl->vfps));
 	assert(VTAILQ_EMPTY(&vcl->vdps));
 	AZ(dlclose(vcl->dlh));
@@ -878,7 +876,7 @@ vcl_cli_discard(struct cli *cli, const char * const *av, void *priv)
 	(void)cli;
 	AZ(priv);
 	vcl = vcl_find(av[2]);
-	AN(vcl);			// MGT ensures this
+	CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);		// MGT ensures this
 	Lck_Lock(&vcl_mtx);
 	assert (vcl != vcl_active);	// MGT ensures this
 	AZ(vcl->nlabels);		// MGT ensures this
diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index 485915c11..1baf344f5 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -80,6 +80,7 @@ VRT_AddVFP(VRT_CTX, const struct vfp *filter)
 	}
 	if (ctx != NULL) {
 		ASSERT_CLI();
+		CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
 		hd = &ctx->vcl->vfps;
 		VTAILQ_FOREACH(vp, hd, list) {
 			xxxassert(vp->vfp != filter);
@@ -111,6 +112,7 @@ VRT_AddVDP(VRT_CTX, const struct vdp *filter)
 	}
 	if (ctx != NULL) {
 		ASSERT_CLI();
+		CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
 		hd = &ctx->vcl->vdps;
 		VTAILQ_FOREACH(vp, hd, list) {
 			xxxassert(vp->vdp != filter);
@@ -129,15 +131,18 @@ void
 VRT_RemoveVFP(VRT_CTX, const struct vfp *filter)
 {
 	struct vfilter *vp;
-	struct vfilter_head *hd = &ctx->vcl->vfps;
+	struct vfilter_head *hd;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
+	hd = &ctx->vcl->vfps;
 	AN(filter);
 	AN(filter->name);
 	AN(*filter->name);
 
 	ASSERT_CLI();
 	VTAILQ_FOREACH(vp, hd, list) {
+		CHECK_OBJ_NOTNULL(vp, VFILTER_MAGIC);
 		if (vp->vfp == filter)
 			break;
 	}
@@ -150,15 +155,18 @@ void
 VRT_RemoveVDP(VRT_CTX, const struct vdp *filter)
 {
 	struct vfilter *vp;
-	struct vfilter_head *hd = &ctx->vcl->vdps;
+	struct vfilter_head *hd;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
+	hd = &ctx->vcl->vdps;
 	AN(filter);
 	AN(filter->name);
 	AN(*filter->name);
 
 	ASSERT_CLI();
 	VTAILQ_FOREACH(vp, hd, list) {
+		CHECK_OBJ_NOTNULL(vp, VFILTER_MAGIC);
 		if (vp->vdp == filter)
 			break;
 	}
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 9b3c25a0f..f7bcf2017 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -143,6 +143,7 @@ vcldir_free(struct vcldir *vdir)
 {
 
 	CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC);
+	CHECK_OBJ_NOTNULL(vdir->dir, DIRECTOR_MAGIC);
 	Lck_Delete(&vdir->dlck);
 	free(vdir->cli_name);
 	FREE_OBJ(vdir->dir);
diff --git a/bin/varnishd/common/common_vsc.c b/bin/varnishd/common/common_vsc.c
index 94cb465cd..0e9128eaa 100644
--- a/bin/varnishd/common/common_vsc.c
+++ b/bin/varnishd/common/common_vsc.c
@@ -198,12 +198,11 @@ VRT_VSC_Destroy(const char *nm, struct vsc_seg *vsg)
 
 	AN(heritage.proc_vsmw);
 	CHECK_OBJ_NOTNULL(vsg, VSC_SEG_MAGIC);
+	CAST_OBJ_NOTNULL(dvsg, vsg->doc, VSC_SEG_MAGIC);
 	AZ(vsg->jp);
-	CHECK_OBJ_NOTNULL(vsg->doc, VSC_SEG_MAGIC);
 	assert(vsg->vsm == heritage.proc_vsmw);
 	assert(vsg->nm == nm);
 
-	dvsg = vsg->doc;
 	VSMW_Free(heritage.proc_vsmw, &vsg->seg);
 	VTAILQ_REMOVE(&vsc_seglist, vsg, list);
 	FREE_OBJ(vsg);
diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index c516a530c..2424947e3 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -316,10 +316,12 @@ hcb_cleaner(struct worker *wrk, void *priv)
 	(void)priv;
 	while (1) {
 		VSTAILQ_FOREACH_SAFE(y, &dead_y, list, y2) {
+			CHECK_OBJ_NOTNULL(y, HCB_Y_MAGIC);
 			VSTAILQ_REMOVE_HEAD(&dead_y, list);
 			FREE_OBJ(y);
 		}
 		VTAILQ_FOREACH_SAFE(oh, &dead_h, hoh_list, oh2) {
+			CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 			VTAILQ_REMOVE(&dead_h, oh, hoh_list);
 			HSH_DeleteObjHead(wrk, oh);
 		}
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index dca5c4b52..9c2a8f0ef 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -827,6 +827,7 @@ main(int argc, char * const *argv)
 	u = 0;
 	while (!VTAILQ_EMPTY(&f_args)) {
 		fa = VTAILQ_FIRST(&f_args);
+		CHECK_OBJ_NOTNULL(fa, F_ARG_MAGIC);
 		VTAILQ_REMOVE(&f_args, fa, list);
 		mgt_vcl_startup(cli, fa->src,
 		    VTAILQ_EMPTY(&f_args) ? "boot" : NULL,
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 95d3864d0..942103d33 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -96,6 +96,7 @@ smp_save_segs(struct smp_sc *sc)
 {
 	struct smp_seg *sg, *sg2;
 
+	CHECK_OBJ_NOTNULL(sc, SMP_SC_MAGIC);
 	Lck_AssertHeld(&sc->mtx);
 
 	/*
@@ -103,6 +104,8 @@ smp_save_segs(struct smp_sc *sc)
 	 * before we write the segments to disk.
 	 */
 	VTAILQ_FOREACH_SAFE(sg, &sc->segments, list, sg2) {
+		CHECK_OBJ_NOTNULL(sg, SMP_SEG_MAGIC);
+
 		if (sg->nobj > 0)
 			break;
 		if (sg == sc->cur_seg)
@@ -265,6 +268,7 @@ smp_close_seg(struct smp_sc *sc, struct smp_seg *sg)
 	uint64_t left, dst, len;
 	void *dp;
 
+	CHECK_OBJ_NOTNULL(sc, SMP_SC_MAGIC);
 	Lck_AssertHeld(&sc->mtx);
 
 	CHECK_OBJ_NOTNULL(sg, SMP_SEG_MAGIC);
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index a73cc0b87..06982c5bf 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -207,6 +207,7 @@ macro_undef(struct vtclog *vl, const char *instance, const char *name)
 	if (m != NULL) {
 		if (!vtc_stop)
 			vtc_log(vl, 4, "macro undef %s", name);
+		CHECK_OBJ(m, MACRO_MAGIC);
 		VTAILQ_REMOVE(&macro_list, m, list);
 		free(m->name);
 		free(m->val);
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 3e310d791..6e0c2846b 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -1777,7 +1777,9 @@ const struct cmds http_cmds[] = {
 static void
 http_process_cleanup(void *arg)
 {
-	struct http *hp = arg;
+	struct http *hp;
+
+	CAST_OBJ_NOTNULL(hp, arg, HTTP_MAGIC);
 
 	if (hp->h2)
 		stop_h2(hp);
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index 15c1a7371..dae3ff0ec 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -98,9 +98,9 @@ vtc_logopen(const char *fmt, ...)
 void
 vtc_logclose(void *arg)
 {
-	struct vtclog *vl = arg;
+	struct vtclog *vl;
 
-	CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC);
+	CAST_OBJ_NOTNULL(vl, arg, VTCLOG_MAGIC);
 	if (pthread_getspecific(log_key) == vl)
 		AZ(pthread_setspecific(log_key, NULL));
 	VSB_destroy(&vl->vsb);
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index bd4d243eb..2194d6621 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -296,6 +296,7 @@ tst_cb(const struct vev *ve, int what)
 	char *p;
 
 	CAST_OBJ_NOTNULL(jp, ve->priv, JOB_MAGIC);
+	CHECK_OBJ_NOTNULL(jp->tst, TST_MAGIC);
 
 	// printf("CB %p %s %d\n", ve, jp->tst->filename, what);
 	if (what == 0) {
diff --git a/lib/libvarnish/vbh.c b/lib/libvarnish/vbh.c
index ce7bd5fd9..02afefa44 100644
--- a/lib/libvarnish/vbh.c
+++ b/lib/libvarnish/vbh.c
@@ -613,7 +613,7 @@ main(void)
 		for (u = 0; u < M; u++) {
 			v = VRND_RandomTestable() % N;
 			if (ff[v] != NULL) {
-				CHECK_OBJ_NOTNULL(ff[v], FOO_MAGIC);
+				CHECK_OBJ(ff[v], FOO_MAGIC);
 				AN(ff[v]->idx);
 				if (ff[v]->key & 1) {
 					VBH_delete(bh, ff[v]->idx);
@@ -639,6 +639,7 @@ main(void)
 		fprintf(stderr, "%d updates OK\n", M);
 	}
 	while ((fp = VBH_root(bh)) != NULL) {
+		CHECK_OBJ(fp, FOO_MAGIC);
 		VBH_delete(bh, fp->idx);
 		FREE_OBJ(fp);
 	}
diff --git a/lib/libvarnish/vfil.c b/lib/libvarnish/vfil.c
index 0720e7f74..8d1f3ab60 100644
--- a/lib/libvarnish/vfil.c
+++ b/lib/libvarnish/vfil.c
@@ -332,6 +332,7 @@ VFIL_setpath(struct vfil_path **pp, const char *path)
 	REPLACE(vp->str, path);
 	while (!VTAILQ_EMPTY(&vp->paths)) {
 		vd = VTAILQ_FIRST(&vp->paths);
+		CHECK_OBJ_NOTNULL(vd, VFIL_DIR_MAGIC);
 		VTAILQ_REMOVE(&vp->paths, vd, list);
 		FREE_OBJ(vd);
 	}
diff --git a/lib/libvarnish/vlu.c b/lib/libvarnish/vlu.c
index d8cb39c5c..217c50b12 100644
--- a/lib/libvarnish/vlu.c
+++ b/lib/libvarnish/vlu.c
@@ -66,10 +66,8 @@ VLU_New(vlu_f *func, void *priv, unsigned bufsize)
 		l->priv = priv;
 		l->bufl = bufsize - 1;
 		l->buf = malloc(l->bufl + 1L);
-		if (l->buf == NULL) {
+		if (l->buf == NULL)
 			FREE_OBJ(l);
-			l = NULL;
-		}
 	}
 	return (l);
 }
diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c
index 6a2040823..1e62184f9 100644
--- a/lib/libvarnish/vre.c
+++ b/lib/libvarnish/vre.c
@@ -294,10 +294,9 @@ VRE_sub(const vre_t *code, const char *subject, const char *replacement,
 void
 VRE_free(vre_t **vv)
 {
-	vre_t *v = *vv;
+	vre_t *v;
 
-	*vv = NULL;
-	CHECK_OBJ(v, VRE_MAGIC);
+	TAKE_OBJ_NOTNULL(v, vv, VRE_MAGIC);
 
 	if (v->re == VRE_PACKED_RE) {
 		v->re = NULL;
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 1a84d6aeb..2fdcfe740 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -319,7 +319,6 @@ vsc_del_seg(const struct vsc *vsc, struct vsm *vsm, struct vsc_seg **spp)
 	struct vsc_seg *sp;
 
 	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
-	AN(vsm);
 	TAKE_OBJ_NOTNULL(sp, spp, VSC_SEG_MAGIC);
 	AZ(VSM_Unmap(vsm, sp->fantom));
 	if (sp->vj != NULL) {
@@ -343,7 +342,6 @@ vsc_add_seg(const struct vsc *vsc, struct vsm *vsm, const struct vsm_fantom *fp)
 	struct vsc_pt *pp;
 
 	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
-	AN(vsm);
 
 	ALLOC_OBJ(sp, VSC_SEG_MAGIC);
 	AN(sp);
diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c
index 6b1284667..b06f7deb5 100644
--- a/lib/libvarnishapi/vsl_cursor.c
+++ b/lib/libvarnishapi/vsl_cursor.c
@@ -79,6 +79,7 @@ vslc_vsm_delete(const struct VSL_cursor *cursor)
 {
 	struct vslc_vsm *c;
 
+	AN(cursor);
 	CAST_OBJ_NOTNULL(c, cursor->priv_data, VSLC_VSM_MAGIC);
 	AZ(VSM_Unmap(c->vsm, &c->vf));
 	assert(&c->cursor == cursor);
@@ -322,6 +323,7 @@ vslc_file_delete(const struct VSL_cursor *cursor)
 {
 	struct vslc_file *c;
 
+	AN(cursor);
 	CAST_OBJ_NOTNULL(c, cursor->priv_data, VSLC_FILE_MAGIC);
 	assert(&c->cursor == cursor);
 	if (c->close_fd)
@@ -418,6 +420,7 @@ vslc_mmap_delete(const struct VSL_cursor *cursor)
 {
 	struct vslc_mmap *c;
 
+	AN(cursor);
 	CAST_OBJ_NOTNULL(c, cursor->priv_data, VSLC_MMAP_MAGIC);
 	assert(&c->cursor == cursor);
 	AZ(munmap(c->b, c->e - c->b));
diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c
index e68fa4e29..4038273d0 100644
--- a/lib/libvarnishapi/vsl_dispatch.c
+++ b/lib/libvarnishapi/vsl_dispatch.c
@@ -375,12 +375,12 @@ chunk_newbuf(struct vtx *vtx, const uint32_t *ptr, size_t len)
 static void
 chunk_freebuf(struct chunk **pchunk)
 {
+	struct chunk *chunk;
 
-	CHECK_OBJ_NOTNULL(*pchunk, CHUNK_MAGIC);
-	assert((*pchunk)->type == chunk_t_buf);
-	free((*pchunk)->buf.data);
-	FREE_OBJ(*pchunk);
-	*pchunk = NULL;
+	TAKE_OBJ_NOTNULL(chunk, pchunk, CHUNK_MAGIC);
+	assert(chunk->type == chunk_t_buf);
+	free(chunk->buf.data);
+	FREE_OBJ(chunk);
 }
 
 /* Append a set of records to a chunk */
@@ -593,9 +593,9 @@ vtx_retire(struct VSLQ *vslq, struct vtx **pvtx)
 	if (vslq->n_cache < VTX_CACHE) {
 		VTAILQ_INSERT_HEAD(&vslq->cache, vtx, list_child);
 		vslq->n_cache++;
-	} else {
+	} else
 		FREE_OBJ(vtx);
-	}
+
 }
 
 /* Lookup a vtx by vxid from the managed list */
@@ -1166,6 +1166,7 @@ VSLQ_Delete(struct VSLQ **pvslq)
 	while (!VTAILQ_EMPTY(&vslq->cache)) {
 		AN(vslq->n_cache);
 		vtx = VTAILQ_FIRST(&vslq->cache);
+		CHECK_OBJ_NOTNULL(vtx, VTX_MAGIC);
 		VTAILQ_REMOVE(&vslq->cache, vtx, list_child);
 		vslq->n_cache--;
 		FREE_OBJ(vtx);
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index 401f278dd..0040e85c8 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -306,9 +306,8 @@ vsm_delset(struct vsm_set **p)
 	struct vsm_set *vs;
 	struct vsm_seg *vg;
 
-	AN(p);
-	vs = *p;
-	*p = NULL;
+	TAKE_OBJ_NOTNULL(vs, p, VSM_SET_MAGIC);
+
 	if (vs->fd >= 0)
 		closefd(&vs->fd);
 	if (vs->dfd >= 0)
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index 82077270a..7c275102e 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -378,7 +378,6 @@ VUT_Fini(struct VUT **vutp)
 	if (vut->vsm)
 		VSM_Destroy(&vut->vsm);
 
-	memset(vut, 0, sizeof *vut);
 	FREE_OBJ(vut);
 }
 
diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c
index 6d346d55d..01cbff89f 100644
--- a/lib/libvarnishapi/vxp_parse.c
+++ b/lib/libvarnishapi/vxp_parse.c
@@ -573,31 +573,37 @@ vxp_Parse(struct vxp *vxp)
 void
 vex_Free(struct vex **pvex)
 {
-
-	if ((*pvex)->lhs != NULL) {
-		if ((*pvex)->lhs->tags != NULL)
-			vbit_destroy((*pvex)->lhs->tags);
-		if ((*pvex)->lhs->prefix != NULL)
-			free((*pvex)->lhs->prefix);
-		FREE_OBJ((*pvex)->lhs);
+	struct vex *vex;
+	struct vex_lhs *lhs;
+	struct vex_rhs *rhs;
+
+	TAKE_OBJ_NOTNULL(vex, pvex, VEX_MAGIC);
+
+	if (vex->lhs) {
+		CAST_OBJ(lhs, vex->lhs, VEX_LHS_MAGIC);
+		if (lhs->tags)
+			vbit_destroy(lhs->tags);
+		if (lhs->prefix)
+			free(lhs->prefix);
+		FREE_OBJ(lhs);
 	}
-	if ((*pvex)->rhs != NULL) {
-		if ((*pvex)->rhs->val_string)
-			free((*pvex)->rhs->val_string);
-		if ((*pvex)->rhs->val_regex)
-			VRE_free(&(*pvex)->rhs->val_regex);
-		FREE_OBJ((*pvex)->rhs);
+	if (vex->rhs) {
+		CAST_OBJ(rhs, vex->rhs, VEX_RHS_MAGIC);
+		if (rhs->val_string)
+			free(rhs->val_string);
+		if (rhs->val_regex)
+			VRE_free(&rhs->val_regex);
+		FREE_OBJ(rhs);
 	}
-	if ((*pvex)->a != NULL) {
-		vex_Free(&(*pvex)->a);
-		AZ((*pvex)->a);
+	if (vex->a) {
+		vex_Free(&vex->a);
+		AZ(vex->a);
 	}
-	if ((*pvex)->b != NULL) {
-		vex_Free(&(*pvex)->b);
-		AZ((*pvex)->b);
+	if (vex->b) {
+		vex_Free(&vex->b);
+		AZ(vex->b);
 	}
-	FREE_OBJ(*pvex);
-	*pvex = NULL;
+	FREE_OBJ(vex);
 }
 
 #ifdef VXP_DEBUG
diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index 557b3a21f..96360b8d3 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -87,11 +87,11 @@ struct acl_e {
 static void
 vcl_acl_free(struct acl_e **aep)
 {
-	AN(aep);
-	CHECK_OBJ_NOTNULL(*aep, VCC_ACL_E_MAGIC);
-	if ((*aep)->addr != NULL)
-		free((*aep)->addr);
-	FREE_OBJ(*aep);
+	struct acl_e *a;
+
+	TAKE_OBJ_NOTNULL(a, aep, VCC_ACL_E_MAGIC);
+	free(a->addr);
+	FREE_OBJ(a);
 }
 
 static int
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index d40417baa..28a3f4402 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -118,7 +118,7 @@ vcc_delete_expr(struct expr *e)
 {
 	if (e == NULL)
 		return;
-	CHECK_OBJ_NOTNULL(e, EXPR_MAGIC);
+	CHECK_OBJ(e, EXPR_MAGIC);
 	VSB_destroy(&e->vsb);
 	FREE_OBJ(e);
 }
diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c
index f75016da0..240f5d281 100644
--- a/vmod/vmod_debug.c
+++ b/vmod/vmod_debug.c
@@ -422,7 +422,6 @@ priv_vcl_fini(VRT_CTX, void *priv)
 	AZ(priv_vcl->vclref_discard);
 	AZ(priv_vcl->vclref_cold);
 	FREE_OBJ(priv_vcl);
-	AZ(priv_vcl);
 }
 
 static const struct vmod_priv_methods priv_vcl_methods[1] = {{
@@ -747,11 +746,10 @@ VCL_VOID
 xyzzy_concat__fini(struct xyzzy_debug_concat **concatp)
 {
 	struct xyzzy_debug_concat *concat;
-	void *p;
+
 
 	TAKE_OBJ_NOTNULL(concat, concatp, CONCAT_MAGIC);
-	p = TRUST_ME(concat->s);
-	free(p);
+	free(TRUST_ME(concat->s));
 	FREE_OBJ(concat);
 }
 
@@ -1366,9 +1364,7 @@ xyzzy_caller__fini(struct VPFX(debug_caller) **callerp)
 
 	if (callerp == NULL || *callerp == NULL)
 		return;
-	CHECK_OBJ(*callerp, DEBUG_CALLER_MAGIC);
-	caller = *callerp;
-	*callerp = NULL;
+	TAKE_OBJ_NOTNULL(caller, callerp, DEBUG_CALLER_MAGIC);
 	FREE_OBJ(caller);
 }
 
diff --git a/vmod/vmod_debug_obj.c b/vmod/vmod_debug_obj.c
index f5e92a2e5..ac3bab0d1 100644
--- a/vmod/vmod_debug_obj.c
+++ b/vmod/vmod_debug_obj.c
@@ -339,9 +339,6 @@ xyzzy_obj_opt__fini(struct xyzzy_debug_obj_opt **op)
 {
 	struct xyzzy_debug_obj_opt *o;
 
-	AN(op);
-	AN(*op);
-
 	TAKE_OBJ_NOTNULL(o, op, VMOD_DEBUG_OBJ_OPT_MAGIC);
 
 	REPLACE(o->name, NULL);
@@ -350,7 +347,6 @@ xyzzy_obj_opt__fini(struct xyzzy_debug_obj_opt **op)
 		REPLACE(o->freeptr, NULL);
 	}
 	FREE_OBJ(o);
-	AZ(o);
 }
 
 VCL_STRING v_matchproto_()
diff --git a/vmod/vmod_directors_fall_back.c b/vmod/vmod_directors_fall_back.c
index ac79dae47..0e5d159cb 100644
--- a/vmod/vmod_directors_fall_back.c
+++ b/vmod/vmod_directors_fall_back.c
@@ -180,6 +180,7 @@ vmod_fallback_destroy(VCL_BACKEND dir)
 {
 	struct vmod_directors_fallback *fallback;
 
+	CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(fallback, dir->priv, VMOD_DIRECTORS_FALLBACK_MAGIC);
 	vdir_delete(&fallback->vd);
 	FREE_OBJ(fallback);
diff --git a/vmod/vmod_directors_hash.c b/vmod/vmod_directors_hash.c
index 2ab92fb7c..cfa212b1c 100644
--- a/vmod/vmod_directors_hash.c
+++ b/vmod/vmod_directors_hash.c
@@ -50,6 +50,7 @@ vmod_hash_destroy(VCL_BACKEND dir)
 {
 	struct vmod_directors_hash *rr;
 
+	CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_HASH_MAGIC);
 	vdir_delete(&rr->vd);
 	FREE_OBJ(rr);
diff --git a/vmod/vmod_directors_random.c b/vmod/vmod_directors_random.c
index 8fe711931..f58acd702 100644
--- a/vmod/vmod_directors_random.c
+++ b/vmod/vmod_directors_random.c
@@ -91,6 +91,7 @@ vmod_random_destroy(VCL_BACKEND dir)
 {
 	struct vmod_directors_random *rr;
 
+	CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
 	vdir_delete(&rr->vd);
 	FREE_OBJ(rr);
diff --git a/vmod/vmod_directors_round_robin.c b/vmod/vmod_directors_round_robin.c
index b365a7116..1cc6ac82d 100644
--- a/vmod/vmod_directors_round_robin.c
+++ b/vmod/vmod_directors_round_robin.c
@@ -101,6 +101,7 @@ vmod_rr_destroy(VCL_BACKEND dir)
 {
 	struct vmod_directors_round_robin *rr;
 
+	CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_ROUND_ROBIN_MAGIC);
 	vdir_delete(&rr->vd);
 	FREE_OBJ(rr);


More information about the varnish-commit mailing list