From 9dc605355a34deb2d85d09680a64faff8af11e65 Mon Sep 17 00:00:00 2001 From: Eric Salama Date: Fri, 18 Sep 2020 11:55:17 +0200 Subject: [PATCH] BUG/MINOR: Fix memory leaks cfg_parse_peers When memory allocation fails in cfg_parse_peers or when an error occurs while parsing a stick-table, the temporary table and its id must be freed. This fixes github issue #854. It should be backported as far as 2.0. (cherry picked from commit 1aab911017e0634c109325eff73d5d49325babed) Signed-off-by: Willy Tarreau (cherry picked from commit 7623beb5192955bdc40aaad218df497e3378d716) Signed-off-by: Willy Tarreau --- src/cfgparse.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index 0cd07b7..22bcced 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -923,13 +923,18 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) if (!t || !id) { ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n", file, linenum, args[0], args[1]); + free(t); + free(id); err_code |= ERR_ALERT | ERR_FATAL; goto out; } err_code |= parse_stick_table(file, linenum, args, t, id, id + prefix_len, curpeers); - if (err_code & ERR_FATAL) + if (err_code & ERR_FATAL) { + free(t); + free(id); goto out; + } stktable_store_name(t); t->next = stktables_list; -- 1.7.10.4