]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: protocol: fix minor memory leak in protocol_bind_all()
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 7 Feb 2023 14:51:58 +0000 (15:51 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 23 Feb 2023 14:05:05 +0000 (15:05 +0100)
In protocol_bind_all() (involved in startup sequence):
We only free errmsg (set by fam->bind() attempt) when we make use of it.
But this could lead to some memory leaks because there are some cases
where we ignore the error message (e.g: verbose=0 with ERR_WARN messages).

As long as errmsg is set, we should always free it.

As mentioned earlier, this really is a minor leak because it can only occur on
specific conditions (error paths) during the startup phase.

This may be backported up to 2.4.

--
Backport notes:

-> 2.4 only:

Replace this:

    |                                        ha_warning("Binding [%s:%d] for %s %s: %s\n",
    |                                                   listener->bind_conf->file, listener->bind_conf->line,
    |                                                   proxy_type_str(px), px->id, errmsg);

By this:

    |                                else if (lerr & ERR_WARN)
    |                                        ha_warning("Starting %s %s: %s\n",
    |                                                   proxy_type_str(px), px->id, errmsg);

src/protocol.c

index cafaa72e702b5543469d914825fc5107c3ec17ab..62091a51b014e69bcb3851e4d071975f854de416 100644 (file)
@@ -99,8 +99,10 @@ int protocol_bind_all(int verbose)
                                        ha_warning("Binding [%s:%d] for %s %s: %s\n",
                                                   listener->bind_conf->file, listener->bind_conf->line,
                                                   proxy_type_str(px), px->id, errmsg);
-                               ha_free(&errmsg);
                        }
+                       if (lerr != ERR_NONE)
+                               ha_free(&errmsg);
+
                        if (lerr & ERR_ABORT)
                                break;