]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stats: free dynamically stats fields/lines on shutdown
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 10 Nov 2020 13:24:30 +0000 (14:24 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 Nov 2020 14:16:05 +0000 (15:16 +0100)
Register a new function on POST DEINIT to free stats fields/lines for
each domain.

This patch does not fix a critical bug but may be backported to 2.3.

src/stats.c

index 762672f45e5d43719a9e9d44da736931fb87ebf2..ad92d71593bb809d81355a58c19ab48a03616e29 100644 (file)
@@ -4548,6 +4548,23 @@ static int allocate_stats_dns_postcheck(void)
 
 REGISTER_CONFIG_POSTPARSER("allocate-stats-dns", allocate_stats_dns_postcheck);
 
+static void deinit_stats(void)
+{
+       int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_DNS }, i;
+
+       for (i = 0; i < STATS_DOMAIN_COUNT; ++i) {
+               const int domain = domains[i];
+
+               if (stat_l[domain])
+                       free(stat_l[domain]);
+
+               if (stat_f[domain])
+                       free(stat_f[domain]);
+       }
+}
+
+REGISTER_POST_DEINIT(deinit_stats);
+
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
        { { "clear", "counters",  NULL }, "clear counters : clear max statistics counters (add 'all' for all counters)", cli_parse_clear_counters, NULL, NULL },