[master] 75b1392 Make sure any halfbaked object is always deallocated when we hit stp_error and make a new object.

Poul-Henning Kamp phk at FreeBSD.org
Wed Sep 16 23:31:58 CEST 2015


commit 75b1392b8f67cf3bf522e85d0af7f2e9848748d0
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Sep 16 21:31:29 2015 +0000

    Make sure any halfbaked object is always deallocated when
    we hit stp_error and make a new object.

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index a69862f..262d791 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -658,17 +658,15 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 		vbf_fetch_body_helper(bo);
 	}
 
-	if (bo->vfc->failed && !bo->do_stream) {
-		assert(bo->state < BOS_STREAM);
-		ObjFreeObj(bo->wrk, bo->fetch_objcore);
-		// XXX: doclose = ?
-		VDI_Finish(bo->wrk, bo);
-		return (F_STP_ERROR);
-	}
-
 	if (bo->vfc->failed) {
 		VDI_Finish(bo->wrk, bo);
-		return (F_STP_FAIL);
+		if (!bo->do_stream) {
+			assert(bo->state < BOS_STREAM);
+			// XXX: doclose = ?
+			return (F_STP_ERROR);
+		} else {
+			return (F_STP_FAIL);
+		}
 	}
 
 	if (bo->do_stream)
@@ -775,8 +773,12 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	CHECK_OBJ_NOTNULL(bo->fetch_objcore, OBJCORE_MAGIC);
 	assert(bo->director_state == DIR_S_NULL);
 
+	if(bo->fetch_objcore->stobj->stevedore != NULL)
+		ObjFreeObj(bo->wrk, bo->fetch_objcore);
+
 	now = W_TIM_real(wrk);
 	VSLb_ts_busyobj(bo, "Error", now);
 
@@ -792,10 +794,8 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 	http_TimeHeader(bo->beresp, "Date: ", now);
 	http_SetHeader(bo->beresp, "Server: Varnish");
 
+	EXP_Clr(&bo->fetch_objcore->exp);
 	bo->fetch_objcore->exp.t_origin = bo->t_prev;
-	bo->fetch_objcore->exp.ttl = 0;
-	bo->fetch_objcore->exp.grace = 0;
-	bo->fetch_objcore->exp.keep = 0;
 
 	VCL_backend_error_method(bo->vcl, wrk, NULL, bo, synth_body);
 
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 41c6c9e..57e06b8 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -52,6 +52,7 @@ obj_getmethods(const struct objcore *oc)
 {
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	AN(oc->stobj->stevedore);
 	CHECK_OBJ_NOTNULL(oc->stobj->stevedore, STEVEDORE_MAGIC);
 	AN(oc->stobj->stevedore->methods);
 	return (oc->stobj->stevedore->methods);
@@ -443,6 +444,7 @@ ObjFreeObj(struct worker *wrk, struct objcore *oc)
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	AN(m->freeobj);
 	m->freeobj(wrk, oc);
+	AZ(oc->stobj->stevedore);
 }
 
 /*====================================================================
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 8119aad..3a5698d 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -508,6 +508,7 @@ smp_oc_freeobj(struct worker *wrk, struct objcore *oc)
 	}
 
 	Lck_Unlock(&sg->sc->mtx);
+	memset(oc->stobj, 0, sizeof oc->stobj);
 }
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list