From: Tim Duesterhus Date: Sun, 3 Jan 2021 19:04:36 +0000 (+0100) Subject: BUG/MINOR: lua: Fix memory leak error cases in hlua_config_prepend_path X-Git-Tag: v2.4-dev5~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=621e74afd1f9d4f9f65812c8befcafb0ba0aff37;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/hlua.c b/src/hlua.c index b6138251aa..7ac0274a26 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 */