]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: log: fix memory leak on logsrv parse error
authorWilly Tarreau <w@1wt.eu>
Tue, 27 Oct 2020 08:51:37 +0000 (09:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 27 Oct 2020 08:55:00 +0000 (09:55 +0100)
In case of parsing error on logsrv, we can leave parse_logsrv() without
releasing logsrv->ring_name or smp_rgs. Let's free them on the error path.
This should fix issue #926 detected by Coverity.

The impact is only a tiny leak just before reporting a fatal error, so it
will essentially annoy valgrind.

This can be backported to 2.0 (just drop the ring part).

src/log.c

index ffd826332900282690d7e2b3434b7252af9f1cef..55fa4d51ae948abaa48ca4354cfb687af352898d 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -799,6 +799,7 @@ int smp_log_range_cmp(const void *a, const void *b)
  */
 int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
 {
+       struct smp_log_range *smp_rgs = NULL;
        struct sockaddr_storage *sk;
        struct logsrv *logsrv = NULL;
        int port1, port2;
@@ -905,7 +906,6 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
        if (strcmp(args[cur_arg], "sample") == 0) {
                unsigned low, high;
                char *p, *beg, *end, *smp_sz_str;
-               struct smp_log_range *smp_rgs = NULL;
                size_t smp_rgs_sz = 0, smp_sz = 0, new_smp_sz;
 
                p = args[cur_arg+1];
@@ -1038,6 +1038,8 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
        return 1;
 
   error:
+       free(smp_rgs);
+       free(logsrv->ring_name);
        free(logsrv);
        return 0;
 }