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.
diff --git a/src/dns.c b/src/dns.c
index bfd22c1..716514b 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -934,9 +934,10 @@
 		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 @@
 	/* Error unrolling */
  out_free_addr:
 	sockaddr_free(&addr);
- out_free_sess:
-	session_free(sess);
  out_free_appctx:
 	appctx_free(appctx);
  out_close:
diff --git a/src/flt_spoe.c b/src/flt_spoe.c
index 030ba9c..c176a9b 100644
--- a/src/flt_spoe.c
+++ b/src/flt_spoe.c
@@ -2026,9 +2026,10 @@
 	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 @@
 	return appctx;
 
 	/* Error unrolling */
- out_free_sess:
-	session_free(sess);
  out_free_spoe:
 	task_destroy(SPOE_APPCTX(appctx)->task);
  out_free_spoe_appctx:
diff --git a/src/hlua.c b/src/hlua.c
index abe3556..193956a 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2994,10 +2994,11 @@
 		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 @@
 
 	return 1;
 
- out_fail_sess:
-	session_free(sess);
  out_fail_appctx:
 	appctx_free(appctx);
  out_fail_conf:
diff --git a/src/http_client.c b/src/http_client.c
index 4daacea..b818396 100644
--- a/src/http_client.c
+++ b/src/http_client.c
@@ -578,6 +578,7 @@
 		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 @@
 				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 @@
 
 out_free_addr:
 	sockaddr_free(&addr);
-out_free_sess:
-	session_free(sess);
 out_free_appctx:
 	appctx_free(appctx);
 out:
diff --git a/src/peers.c b/src/peers.c
index 58f771b..07520a4 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -3190,14 +3190,15 @@
 		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 @@
 	/* Error unrolling */
  out_free_addr:
 	sockaddr_free(&addr);
- out_free_sess:
-	session_free(sess);
  out_free_appctx:
 	appctx_free(appctx);
  out_close:
diff --git a/src/sink.c b/src/sink.c
index c52afc6..5939185 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -650,14 +650,15 @@
 		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 @@
 	/* Error unrolling */
  out_free_addr:
 	sockaddr_free(&addr);
- out_free_sess:
-	session_free(sess);
  out_free_appctx:
 	appctx_free(appctx);
  out_close:
diff --git a/src/stream.c b/src/stream.c
index c700236..00abce6 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -585,7 +585,6 @@
 	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 @@
 	}
 	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 */