Hello,
I just started working at Varnish Software (last Thursday), and I am
looking forward to working with the Varnish Cache code. After firm
guidance from Martin, I am proposing my first patch.

Best Regards,

Pål Hermunn Johansen
From 1639f1608ea8dd021f3541d7a41f896bdc95ad8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A5l=20Hermunn=20Johansen?=
 <[email protected]>
Date: Tue, 8 Mar 2016 11:09:20 +0100
Subject: [PATCH] Use calloc instead of malloc to allocate extra VSM space.

With malloc we would read from uninitialized memory (implicitly with ++ or +=).

Also expanded comment: When we need to allocate extra VSM space with malloc/calloc, the space
will not be available to other processes. The workaround is to increase VSM space through the
runtime parameter vsm_space.
---
 bin/varnishd/common/common_vsm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/bin/varnishd/common/common_vsm.c b/bin/varnishd/common/common_vsm.c
index 94d583d..9e798da 100644
--- a/bin/varnishd/common/common_vsm.c
+++ b/bin/varnishd/common/common_vsm.c
@@ -231,12 +231,15 @@ VSM_common_alloc(struct vsm_sc *sc, ssize_t size,
 	}
 
 	if (vr == NULL) {
-		/*
-		 * No space in VSM, return malloc'd space
+		/* No space in VSM, return malloc'd space. The variables
+		 * sc->g_overflow and sc->g_overflow (available from
+		 * varnishstat) will tell you by how much the VSM should
+		 * be expanded do avoild overflow. The malloced space will
+		 * not be availibe to other processes.
 		 */
 		ALLOC_OBJ(vr, VSM_RANGE_MAGIC);
 		AN(vr);
-		vr->ptr = malloc(size);
+		vr->ptr = calloc(size, 1);
 		AN(vr->ptr);
 		vr->len = size;
 		VTAILQ_INSERT_TAIL(&sc->r_bogus, vr, list);
-- 
2.1.4

_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to