]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: state-file: do not allocate a full buffer for each server entry
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Dec 2019 16:18:13 +0000 (17:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Dec 2019 16:18:13 +0000 (17:18 +0100)
Starting haproxy with a state file of 700k servers eats 11.2 GB of RAM
due to a mistake in the function that loads the strings into a tree: it
allocates a full buffer for each backend+server name instead of allocating
just the required string. By just fixing this we're down to 80 MB.

This should be backported to 2.1.

src/server.c

index 3465db97c3cc4e1ffe325c44cc2111fd3b8b5417..718ca1c4003fc571e07061d6894ab0eb40c87058 100644 (file)
@@ -3627,11 +3627,11 @@ void apply_server_state(void)
                        chunk_printf(&trash, "%s %s", bkname, srvname);
 
                        /* store line in tree */
-                       st = calloc(1, sizeof(*st) + trash.size);
+                       st = calloc(1, sizeof(*st) + trash.data + 1);
                        if (st == NULL) {
                                goto nextline;
                        }
-                       memcpy(st->name_name.key, trash.area, trash.size);
+                       memcpy(st->name_name.key, trash.area, trash.data + 1);
                        ebst_insert(&state_file, &st->name_name);
 
                        /* save line */