From 621e74afd1f9d4f9f65812c8befcafb0ba0aff37 Mon Sep 17 00:00:00 2001 From: Tim Duesterhus Date: Sun, 3 Jan 2021 20:04:36 +0100 Subject: [PATCH] BUG/MINOR: lua: Fix memory leak error cases in hlua_config_prepend_path In case of an error `p` is not properly freed. Minor leak during configuration parsing in out of memory situations, no backport needed. --- src/hlua.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index b613825..7ac0274 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -8362,22 +8362,22 @@ static int hlua_config_prepend_path(char **args, int section_type, struct proxy { char *path; char *type = "path"; - struct prepend_path *p; + struct prepend_path *p = NULL; if (too_many_args(2, args, err, NULL)) { - return -1; + goto err; } if (!(*args[1])) { memprintf(err, "'%s' expects to receive a as argument", args[0]); - return -1; + goto err; } path = args[1]; if (*args[2]) { if (strcmp(args[2], "path") != 0 && strcmp(args[2], "cpath") != 0) { memprintf(err, "'%s' expects to either be 'path' or 'cpath'", args[0]); - return -1; + goto err; } type = args[2]; } @@ -8385,23 +8385,30 @@ static int hlua_config_prepend_path(char **args, int section_type, struct proxy p = calloc(1, sizeof(*p)); if (p == NULL) { memprintf(err, "out of memory error"); - return -1; + goto err; } p->path = strdup(path); if (p->path == NULL) { memprintf(err, "out of memory error"); - return -1; + goto err2; } p->type = strdup(type); if (p->type == NULL) { memprintf(err, "out of memory error"); - return -1; + goto err2; } LIST_ADDQ(&prepend_path_list, &p->l); hlua_prepend_path(hlua_states[0], type, path); hlua_prepend_path(hlua_states[1], type, path); return 0; + +err2: + free(p->type); + free(p->path); +err: + free(p); + return -1; } /* configuration keywords declaration */ -- 1.7.10.4