]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: cache: Fix leak of cconf->c.name during config check
authorTim Duesterhus <tim@bastelstu.be>
Mon, 14 Sep 2020 16:01:33 +0000 (18:01 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 7 Oct 2020 12:07:29 +0000 (14:07 +0200)
During the config check, the post parsing is not performed. Thus, cache filters
are not fully initialized and their cache name are never released. To be able to
release them, a flag is now set when a cache filter is fully initialized. On
deinit, if the flag is not set, it means the cache name must be freed.

The patch should fix #849. No backport needed.

[Cf: Tim is the patch author, but I added the commit message]

src/cache.c

index b42262948a80904d31d08d24b2171b50f7a932e4..fe213a6aae872a0a2861fa43a150960512e3bbf2 100644 (file)
@@ -33,6 +33,7 @@
 
 #define CACHE_FLT_F_IMPLICIT_DECL  0x00000001 /* The cache filtre was implicitly declared (ie without
                                               * the filter keyword) */
+#define CACHE_FLT_INIT             0x00000002 /* Whether the cache name was freed. */
 
 const char *cache_store_flt_id = "cache store filter";
 
@@ -133,6 +134,8 @@ cache_store_deinit(struct proxy *px, struct flt_conf *fconf)
 {
        struct cache_flt_conf *cconf = fconf->conf;
 
+       if (!(cconf->flags & CACHE_FLT_INIT))
+               free(cconf->c.name);
        free(cconf);
 }
 
@@ -1376,6 +1379,7 @@ int post_check_cache()
                                cconf = fconf->conf;
                                if (!strcmp(cache->id, cconf->c.name)) {
                                        free(cconf->c.name);
+                                       cconf->flags |= CACHE_FLT_INIT;
                                        cconf->c.cache = cache;
                                        break;
                                }