r2874 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Jul 1 21:30:11 CEST 2008


Author: phk
Date: 2008-07-01 21:30:11 +0200 (Tue, 01 Jul 2008)
New Revision: 2874

Modified:
   trunk/varnish-cache/bin/varnishd/cache_dir_random.c
Log:
Fix cleanup errors on random director: release all backends.



Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2008-07-01 19:29:01 UTC (rev 2873)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2008-07-01 19:30:11 UTC (rev 2874)
@@ -57,12 +57,14 @@
 	struct director		dir;
 	struct backend		*backend;
 	struct vdi_random_host	*hosts;
+	unsigned		nhosts;
 };
 
 
 static struct backend *
 vdi_random_choose(struct sess *sp)
 {
+	int i;
 	struct vdi_random *vs;
 	uint32_t r;
 	struct vdi_random_host *vh;
@@ -72,7 +74,7 @@
 	r = random();
 	r &= 0x7fffffff;
 
-	for (vh = vs->hosts; ; vh++)
+	for (vh = vs->hosts; i < vs->nhosts; vh++)
 		if (r < vh->weight)
 			return (vh->backend);
 	assert(0 == __LINE__);
@@ -82,14 +84,19 @@
 static void
 vdi_random_fini(struct director *d)
 {
+	int i;
 	struct vdi_random *vs;
+	struct vdi_random_host *vh;
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_RANDOM_MAGIC);
 	
-	VBE_DropRef(vs->backend);
+	vh = vs->hosts;
+	for (i = 0; i < vs->nhosts; i++, vh++)
+		VBE_DropRef(vh->backend);
 	free(vs->hosts);
-	free(vs);
+	vs->dir.magic = 0;
+	FREE_OBJ(vs);
 }
 
 void
@@ -104,12 +111,11 @@
 	
 	(void)cli;
 
-	vs = calloc(sizeof *vs, 1);
+	ALLOC_OBJ(vs, VDI_RANDOM_MAGIC);
 	XXXAN(vs);
 	vs->hosts = calloc(sizeof *vh, t->nmember);
 	XXXAN(vs->hosts);
 
-	vs->magic = VDI_RANDOM_MAGIC;
 	vs->dir.magic = DIRECTOR_MAGIC;
 	vs->dir.priv = vs;
 	vs->dir.name = "random";
@@ -124,6 +130,7 @@
 		s += te->weight;
 		vh->backend = VBE_AddBackend(cli, te->host);
 	}
+	vs->nhosts = t->nmember;
 
 	/* Normalize weights */
 	i = 0;




More information about the varnish-commit mailing list