diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index a7402ca569e..74a7f4e0f0b 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -345,10 +345,9 @@ vdp_gunzip_fini(struct vdp_ctx *vdc, void **priv) struct vgz *vg; (void)vdc; - CAST_OBJ_NOTNULL(vg, *priv, VGZ_MAGIC); + TAKE_OBJ_NOTNULL(vg, priv, VGZ_MAGIC); AN(vg->m_buf); (void)VGZ_Destroy(&vg); - *priv = NULL; return (0); } diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c index a9a86abc2f3..8bdd8e8df4b 100644 --- a/bin/varnishd/cache/cache_range.c +++ b/bin/varnishd/cache/cache_range.c @@ -54,13 +54,13 @@ vrg_range_fini(struct vdp_ctx *vdc, void **priv) struct vrg_priv *vrg_priv; CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - CAST_OBJ_NOTNULL(vrg_priv, *priv, VRG_PRIV_MAGIC); + TAKE_OBJ_NOTNULL(vrg_priv, priv, VRG_PRIV_MAGIC); if (vrg_priv->req->resp_len >= 0 && vrg_priv->range_off < vrg_priv->range_high) { Req_Fail(vrg_priv->req, SC_RANGE_SHORT); vrg_priv->req->vdc->retval = -1; } - *priv = NULL; /* struct on ws, no need to free */ + /* struct on ws, no need to free */ return (0); } diff --git a/tools/coccinelle/take_obj_notnull.cocci b/tools/coccinelle/take_obj_notnull.cocci index f99009c0615..04ad2f13458 100644 --- a/tools/coccinelle/take_obj_notnull.cocci +++ b/tools/coccinelle/take_obj_notnull.cocci @@ -75,13 +75,15 @@ expression obj, priv, magic; @@ - CAST_OBJ_NOTNULL(obj, *priv, magic); -- *priv = NULL; + TAKE_OBJ_NOTNULL(obj, priv, magic); +... +- *priv = NULL; @@ expression obj, priv, magic; @@ - CAST_OBJ_NOTNULL(obj, priv, magic); -- priv = NULL; + TAKE_OBJ_NOTNULL(obj, &priv, magic); +... +- priv = NULL; diff --git a/vmod/vmod_debug_filters.c b/vmod/vmod_debug_filters.c index e0de9ba19c1..f810e8d683d 100644 --- a/vmod/vmod_debug_filters.c +++ b/vmod/vmod_debug_filters.c @@ -292,11 +292,10 @@ xyzzy_pedantic_fini(struct vdp_ctx *vdc, void **priv) AN(priv); if (*priv == NULL) return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_STATE_MAGIC); + TAKE_OBJ_NOTNULL(vdps, priv, VDP_STATE_MAGIC); assert(vdps->state == VDPS_INIT || vdps->state == VDPS_END); vdps->state = VDPS_FINI; - *priv = NULL; return (0); } @@ -497,8 +496,7 @@ xyzzy_chksha256_fini(struct vdp_ctx *vdc, void **priv) AN(priv); if (*priv == NULL) return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); - *priv = NULL; + TAKE_OBJ_NOTNULL(vdps, priv, VDP_CHKSHA256_MAGIC); VSHA256_Final(digest, vdps->cx); r = memcmp(digest, vdps->cfg->expected, sizeof digest); @@ -542,8 +540,7 @@ xyzzy_chkcrc32_fini(struct vdp_ctx *vdc, void **priv) AN(priv); if (*priv == NULL) return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); - *priv = NULL; + TAKE_OBJ_NOTNULL(vdps, priv, VDP_CHKCRC32_MAGIC); if (vdps->crc == vdps->cfg->expected) return (0);