[master] 4743b17 Deref the sess in SES_Delete() and release the storage on ref==0
Poul-Henning Kamp
phk at FreeBSD.org
Wed Apr 6 00:09:05 CEST 2016
commit 4743b17b0fb3b11525d6a4a0aeac959f68d0b396
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Apr 5 21:57:19 2016 +0000
Deref the sess in SES_Delete() and release the storage on ref==0
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 6088fae..6c0e45f 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -507,11 +507,8 @@ SES_Close(struct sess *sp, enum sess_close reason)
void
SES_Delete(struct sess *sp, enum sess_close reason, double now)
{
- struct pool *pp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- pp = sp->pool;
- CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
if (reason != SC_NULL)
SES_Close(sp, reason);
@@ -529,9 +526,7 @@ SES_Delete(struct sess *sp, enum sess_close reason, double now)
VSL(SLT_SessClose, sp->vxid, "%s %.3f",
sess_close_2str(reason, 0), now - sp->t_open);
VSL(SLT_End, sp->vxid, "%s", "");
-
- Lck_Delete(&sp->mtx);
- MPL_Free(pp->mpl_sess, sp);
+ SES_Rel(sp);
}
/*--------------------------------------------------------------------
@@ -551,12 +546,21 @@ SES_Ref(struct sess *sp)
void
SES_Rel(struct sess *sp)
{
+ int i;
+ struct pool *pp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ pp = sp->pool;
+ CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
+
Lck_Lock(&sp->mtx);
assert(sp->refcnt > 0);
- sp->refcnt--;
+ i = --sp->refcnt;
Lck_Unlock(&sp->mtx);
+ if (i)
+ return;
+ Lck_Delete(&sp->mtx);
+ MPL_Free(sp->pool->mpl_sess, sp);
}
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list