[master] 1a708692a Revert "Expend a pointer mere in struct vsb, in an attempt to make it clear for static analysis tools what goes on."

Poul-Henning Kamp phk at FreeBSD.org
Mon Aug 10 09:07:08 UTC 2020


commit 1a708692a30972a60c66580fb2dbe2b5227e87e6
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Aug 10 08:48:56 2020 +0000

    Revert "Expend a pointer mere in struct vsb, in an attempt to make it
            clear for static analysis tools what goes on."
    
    This reverts commit 36225f2ee88f6a5bb4c709e27346962a0e085822.

diff --git a/flint.lnt b/flint.lnt
index 3eb5fbd52..b47a74bdb 100644
--- a/flint.lnt
+++ b/flint.lnt
@@ -185,6 +185,7 @@
 -esym(765, VSB_*)		// extern could be made static
 -esym(714, VSB_*)		// symb not ref
 -sem(VSB_new, @p == (1p ? 1p : malloc(1)))
+-sem(VSB_delete, custodial(1))
 
 // ignore retval
 -esym(534, VSB_cat)
diff --git a/include/vsb.h b/include/vsb.h
index 4041f4c4f..facea9394 100644
--- a/include/vsb.h
+++ b/include/vsb.h
@@ -48,9 +48,9 @@ struct vsb {
 #define	VSB_USRFLAGMSK	0x0000ffff	/* mask of flags the user may specify */
 #define	VSB_DYNAMIC	0x00010000	/* s_buf must be freed */
 #define	VSB_FINISHED	0x00020000	/* set by VSB_finish() */
+#define	VSB_DYNSTRUCT	0x00080000	/* vsb must be freed */
 	int		 s_flags;	/* flags */
 	int		 s_indent;	/* Ident level */
-	void		*s_alloced;	/* Ptr to free, if vsb is malloced */
 };
 
 #ifdef __cplusplus
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index c47977e90..ef9f164b0 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -51,7 +51,8 @@ __FBSDID("$FreeBSD: head/sys/kern/subr_vsb.c 222004 2011-05-17 06:36:32Z phk $")
 /*
  * Predicates
  */
-#define VSB_ISDYNAMIC(s)	((s)->s_flags & VSB_DYNAMIC)
+#define	VSB_ISDYNAMIC(s)	((s)->s_flags & VSB_DYNAMIC)
+#define	VSB_ISDYNSTRUCT(s)	((s)->s_flags & VSB_DYNSTRUCT)
 #define	VSB_HASROOM(s)		((s)->s_len < (s)->s_size - 1L)
 #define	VSB_FREESPACE(s)	((s)->s_size - ((s)->s_len + 1L))
 #define	VSB_CANEXTEND(s)	((s)->s_flags & VSB_AUTOEXTEND)
@@ -231,7 +232,7 @@ VSB_new(struct vsb *s, char *buf, int length, int flags)
 		SBFREE(s);
 		return (NULL);
 	}
-	s->s_alloced = s;
+	VSB_SETFLAG(s, VSB_DYNSTRUCT);
 	return (s);
 }
 
@@ -479,17 +480,17 @@ VSB_len(const struct vsb *s)
 void
 VSB_delete(struct vsb *s)
 {
-	void *p;
+	int isdyn;
 
 	assert_VSB_integrity(s);
 	/* don't care if it's finished or not */
 
 	if (VSB_ISDYNAMIC(s))
 		SBFREE(s->s_buf);
-	p = s->s_alloced;
+	isdyn = VSB_ISDYNSTRUCT(s);
 	memset(s, 0, sizeof(*s));
-	if (p != NULL)
-		SBFREE(p);
+	if (isdyn)
+		SBFREE(s);
 }
 
 void


More information about the varnish-commit mailing list