[master] b25cfdc Simplify http_Teardown() a bit.

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 3 11:28:17 CEST 2014


commit b25cfdc974aec31cd82d9ff3238fad8b25458c08
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 3 09:28:01 2014 +0000

    Simplify http_Teardown() a bit.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index da77ecb..a82ea69 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -186,16 +186,19 @@ struct http {
 	unsigned		magic;
 #define HTTP_MAGIC		0x6428b5c9
 
-	enum VSL_tag_e		logtag;		/* Must be SLT_*Method */
-	struct vsl_log		*vsl;
-
-	struct ws		*ws;
+	uint16_t		shd;		/* Size of hd space */
 	txt			*hd;
 	unsigned char		*hdf;
 #define HDF_FILTER		(1 << 0)	/* Filtered by Connection */
 #define HDF_MARKER		(1 << 1)	/* Marker bit */
-	uint16_t		shd;		/* Size of hd space */
+
+	/* NB: ->nhd and below zeroed/initialized by http_Teardown */
 	uint16_t		nhd;		/* Next free hd */
+
+	enum VSL_tag_e		logtag;		/* Must be SLT_*Method */
+	struct vsl_log		*vsl;
+
+	struct ws		*ws;
 	uint16_t		status;
 	uint8_t			protover;
 	uint8_t			conds;		/* If-* headers present */
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 7fe6c9f..88ff577 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -32,6 +32,7 @@
 #include "config.h"
 
 #include <stdio.h>
+#include <stddef.h>
 
 #include "cache.h"
 
@@ -155,22 +156,13 @@ HTTP_Setup(struct http *hp, struct ws *ws, struct vsl_log *vsl,
 void
 http_Teardown(struct http *hp)
 {
-	uint16_t shd;
-	txt *hd;
-	unsigned char *hdf;
-
-	/* XXX: This is not elegant, is it efficient ? */
-	shd = hp->shd;
-	hd = hp->hd;
-	hdf = hp->hdf;
-	memset(hp, 0, sizeof *hp);
-	memset(hd, 0, sizeof *hd * shd);
-	memset(hdf, 0, sizeof *hdf * shd);
-	hp->magic = HTTP_MAGIC;
+
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
+	AN(hp->shd);
+	memset(&hp->nhd, 0, sizeof *hp - offsetof(struct http, nhd));
+	memset(hp->hd, 0, sizeof *hp->hd * hp->shd);
+	memset(hp->hdf, 0, sizeof *hp->hdf * hp->shd);
 	hp->nhd = HTTP_HDR_FIRST;
-	hp->shd = shd;
-	hp->hd = hd;
-	hp->hdf = hdf;
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list