]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: stconn: fix build warning at -O3 about possible null sc
authorWilly Tarreau <w@1wt.eu>
Thu, 11 Aug 2022 11:56:42 +0000 (13:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 11 Aug 2022 11:59:13 +0000 (13:59 +0200)
gcc-6.x and 7.x emit build warnings about sc possibly being null upon
return from sc_detach_endp(). This actually is not the case and the
compiler is a little bit overzealous there, but there exists code
paths that can make this analysis non-trivial so let's at least add
a similar BUG_ON() to let both the compiler and the deverloper know
this doesn't happen.

This should be backported to 2.6.

src/stconn.c

index 3ffdf51812981ebacde249567b621c28f7d7fa15..36d19b46fea4821e71d77a49a22b65ee584826d6 100644 (file)
@@ -459,6 +459,7 @@ int sc_reset_endp(struct stconn *sc)
 
        /* The app is still attached, the sc will not be released */
        sc_detach_endp(&sc);
+       BUG_ON(!sc);
        BUG_ON(sc->sedesc);
        sc->sedesc = new_sd;
        sc->sedesc->sc = sc;
@@ -1977,5 +1978,6 @@ void sc_conn_commit_endp_upgrade(struct stconn *sc)
                return;
        sc_detach_endp(&sc);
        /* Because it was already set as detached, the sedesc must be preserved */
+       BUG_ON(!sc);
        BUG_ON(!sc->sedesc);
 }