MINOR: applet: Let the frontend appctx release the session

The session created for frontend applets is now totally owns by the
corresponding appctx. It means the appctx is now responsible to release
it. This removes the hack in stream_free() about frontend applets to be sure
to release the session.
This commit is contained in:
Christopher Faulet 2022-05-11 12:22:10 +02:00
parent ac57bb527a
commit 92202da2da
7 changed files with 17 additions and 33 deletions

View File

@ -934,9 +934,10 @@ static struct appctx *dns_session_create(struct dns_session *ds)
ha_alert("out of memory in dns_session_create().\n");
goto out_free_appctx;
}
appctx->sess = sess;
if (!sockaddr_alloc(&addr, &ds->dss->srv->addr, sizeof(ds->dss->srv->addr)))
goto out_free_sess;
goto out_free_appctx;
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
@ -965,8 +966,6 @@ static struct appctx *dns_session_create(struct dns_session *ds)
/* Error unrolling */
out_free_addr:
sockaddr_free(&addr);
out_free_sess:
session_free(sess);
out_free_appctx:
appctx_free(appctx);
out_close:

View File

@ -2026,9 +2026,10 @@ spoe_create_appctx(struct spoe_config *conf)
if (!sess)
goto out_free_spoe;
appctx->sess = sess;
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs)
goto out_free_sess;
goto out_free_spoe;
strm = DISGUISE(cs_strm(cs));
stream_set_backend(strm, conf->agent->b.be);
@ -2049,8 +2050,6 @@ spoe_create_appctx(struct spoe_config *conf)
return appctx;
/* Error unrolling */
out_free_sess:
session_free(sess);
out_free_spoe:
task_destroy(SPOE_APPCTX(appctx)->task);
out_free_spoe_appctx:

View File

@ -2994,10 +2994,11 @@ __LJMP static int hlua_socket_new(lua_State *L)
goto out_fail_appctx;
}
appctx->sess = sess;
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
hlua_pusherror(L, "socket: out of memory");
goto out_fail_sess;
goto out_fail_appctx;
}
s = DISGUISE(cs_strm(cs));
@ -3017,8 +3018,6 @@ __LJMP static int hlua_socket_new(lua_State *L)
return 1;
out_fail_sess:
session_free(sess);
out_fail_appctx:
appctx_free(appctx);
out_fail_conf:

View File

@ -578,6 +578,7 @@ struct appctx *httpclient_start(struct httpclient *hc)
ha_alert("httpclient: out of memory in %s:%d.\n", __FUNCTION__, __LINE__);
goto out_free_appctx;
}
appctx->sess = sess;
/* choose the SSL server or not */
switch (scheme) {
@ -590,22 +591,22 @@ struct appctx *httpclient_start(struct httpclient *hc)
target = &httpclient_srv_ssl->obj_type;
} else {
ha_alert("httpclient: SSL was disabled (wrong verify/ca-file)!\n");
goto out_free_sess;
goto out_free_appctx;
}
#else
ha_alert("httpclient: OpenSSL is not available %s:%d.\n", __FUNCTION__, __LINE__);
goto out_free_sess;
goto out_free_appctx;
#endif
break;
}
if (!ss_dst) {
ha_alert("httpclient: Failed to initialize address %s:%d.\n", __FUNCTION__, __LINE__);
goto out_free_sess;
goto out_free_appctx;
}
if (!sockaddr_alloc(&addr, ss_dst, sizeof(*ss_dst)))
goto out_free_sess;
goto out_free_appctx;
cs = cs_new_from_endp(appctx->endp, sess, &hc->req.buf);
if (!cs) {
@ -650,8 +651,6 @@ struct appctx *httpclient_start(struct httpclient *hc)
out_free_addr:
sockaddr_free(&addr);
out_free_sess:
session_free(sess);
out_free_appctx:
appctx_free(appctx);
out:

View File

@ -3190,14 +3190,15 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
ha_alert("out of memory in peer_session_create().\n");
goto out_free_appctx;
}
appctx->sess = sess;
if (!sockaddr_alloc(&addr, &peer->addr, sizeof(peer->addr)))
goto out_free_sess;
goto out_free_appctx;
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
ha_alert("Failed to initialize stream in peer_session_create().\n");
goto out_free_addr;
goto out_free_appctx;
}
s = DISGUISE(cs_strm(cs));
@ -3224,8 +3225,6 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
/* Error unrolling */
out_free_addr:
sockaddr_free(&addr);
out_free_sess:
session_free(sess);
out_free_appctx:
appctx_free(appctx);
out_close:

View File

@ -650,14 +650,15 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink
ha_alert("out of memory in sink_forward_session_create().\n");
goto out_free_appctx;
}
appctx->sess = sess;
if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr)))
goto out_free_sess;
goto out_free_appctx;
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
ha_alert("Failed to initialize stream in sink_forward_session_create().\n");
goto out_free_addr;
goto out_free_appctx;
}
s = DISGUISE(cs_strm(cs));
@ -682,8 +683,6 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink
/* Error unrolling */
out_free_addr:
sockaddr_free(&addr);
out_free_sess:
session_free(sess);
out_free_appctx:
appctx_free(appctx);
out_close:

View File

@ -585,7 +585,6 @@ static void stream_free(struct stream *s)
struct session *sess = strm_sess(s);
struct proxy *fe = sess->fe;
struct bref *bref, *back;
int must_free_sess;
int i;
DBG_TRACE_POINT(STRM_EV_STRM_FREE, s);
@ -709,18 +708,9 @@ static void stream_free(struct stream *s)
}
LIST_DELETE(&s->list);
/* applets do not release session yet */
/* FIXME: Handle it in appctx_free ??? */
must_free_sess = objt_appctx(sess->origin) && sess->origin == __cs_endp_target(s->csf);
cs_destroy(s->csb);
cs_destroy(s->csf);
if (must_free_sess) {
sess->origin = NULL;
session_free(sess);
}
pool_free(pool_head_stream, s);
/* We may want to free the maximum amount of pools if the proxy is stopping */