From: Willy Tarreau Date: Sat, 4 Apr 2015 14:31:16 +0000 (+0200) Subject: MEDIUM: session: update the session's stick counters upon session_free() X-Git-Tag: v1.6-dev2~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb2ef12a608d5f9bc892e06a3040e4f71a8dc344;p=thirdparty%2Fhaproxy.git MEDIUM: session: update the session's stick counters upon session_free() Whenever session_free() is called, any possible stick counter stored in the session will be synchronized. --- diff --git a/include/proto/session.h b/include/proto/session.h index 487f318ecd..6d45d58059 100644 --- a/include/proto/session.h +++ b/include/proto/session.h @@ -30,10 +30,37 @@ #include #include +#include + extern struct pool_head *pool2_session; void session_free(struct session *sess); int init_session(); +/* Remove the refcount from the session to the tracked counters, and clear the + * pointer to ensure this is only performed once. The caller is responsible for + * ensuring that the pointer is valid first. + */ +static inline void session_store_counters(struct session *sess) +{ + void *ptr; + int i; + + for (i = 0; i < MAX_SESS_STKCTR; i++) { + struct stkctr *stkctr = &sess->stkctr[i]; + + if (!stkctr_entry(stkctr)) + continue; + + ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); + if (ptr) + stktable_data_cast(ptr, conn_cur)--; + stkctr_entry(stkctr)->ref_cnt--; + stksess_kill_if_expired(stkctr->table, stkctr_entry(stkctr)); + stkctr_set_entry(stkctr, NULL); + } +} + + #endif /* _PROTO_SESSION_H */ /* diff --git a/src/session.c b/src/session.c index e1e9f352da..caf8c1439f 100644 --- a/src/session.c +++ b/src/session.c @@ -18,10 +18,13 @@ #include #include +#include + struct pool_head *pool2_session; void session_free(struct session *sess) { + session_store_counters(sess); pool_free2(pool2_session, sess); }