]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stconn: fix sedesc memory leak on stream allocation failure
authorWilly Tarreau <w@1wt.eu>
Mon, 20 Mar 2023 18:53:14 +0000 (19:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 Mar 2023 18:58:38 +0000 (19:58 +0100)
If we fail to allocate a new stream in sc_new_from_endp(), and the call
to sc_new() allocated the sedesc itself (which normally doesn't happen),
then it doesn't get released on the failure path. Let's explicitly
handle this case so that it's not overlooked and avoids some head
scratching sessions.

This may be backported to 2.6.

src/stconn.c

index e1266a4ebce94f368d517255ca8c85763129467f..f84ae6a0f5ea6f5019dec8d33b270c598a59a87e 100644 (file)
@@ -171,8 +171,12 @@ struct stconn *sc_new_from_endp(struct sedesc *sd, struct session *sess, struct
        if (unlikely(!sc))
                return NULL;
        if (unlikely(!stream_new(sess, sc, input))) {
-               pool_free(pool_head_connstream, sc);
                sd->sc = NULL;
+               if (sc->sedesc != sd) {
+                       /* none was provided so sc_new() allocated one */
+                       sedesc_free(sc->sedesc);
+               }
+               pool_free(pool_head_connstream, sc);
                se_fl_set(sd, SE_FL_ORPHAN);
                return NULL;
        }