[master] 53bdce4 Don't waste time allocating a VSB when we reload bans, and in particular don't forget about it so it hangs around with the ban, doing nothing.

Poul-Henning Kamp phk at varnish-cache.org
Thu Nov 22 13:09:33 CET 2012


commit 53bdce4e1b9d6d411466e55d9ac2bbf6a9b602b2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Nov 22 12:08:55 2012 +0000

    Don't waste time allocating a VSB when we reload bans, and in particular
    don't forget about it so it hangs around with the ban, doing nothing.

diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index de23150..8ef4962 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -146,20 +146,31 @@ static const struct pvar {
  * Storage handling of bans
  */
 
+static struct ban *
+ban_alloc(void)
+{
+	struct ban *b;
+
+	ALLOC_OBJ(b, BAN_MAGIC);
+	if (b != NULL)
+		VTAILQ_INIT(&b->objcore);
+	return (b);
+}
+
 struct ban *
 BAN_New(void)
 {
 	struct ban *b;
 
-	ALLOC_OBJ(b, BAN_MAGIC);
-	if (b == NULL)
-		return (b);
-	b->vsb = VSB_new_auto();
-	if (b->vsb == NULL) {
-		FREE_OBJ(b);
-		return (NULL);
+	b = ban_alloc();
+	if (b != NULL) {
+		b->vsb = VSB_new_auto();
+		if (b->vsb == NULL) {
+			FREE_OBJ(b);
+			return (NULL);
+		}
+		VTAILQ_INIT(&b->objcore);
 	}
-	VTAILQ_INIT(&b->objcore);
 	return (b);
 }
 
@@ -577,7 +588,7 @@ BAN_Reload(const uint8_t *ban, unsigned len)
 	VSC_C_main->bans++;
 	VSC_C_main->bans_added++;
 
-	b2 = BAN_New();
+	b2 = ban_alloc();
 	AN(b2);
 	b2->spec = malloc(len);
 	AN(b2->spec);



More information about the varnish-commit mailing list