From 6bce493d25858e252ef2865668b018fa41622660 Mon Sep 17 00:00:00 2001 From: Jim Monte Date: Sat, 30 Mar 2019 09:57:37 +0100 Subject: [PATCH] Remove memory leak: If the check of the data fails, the data itself is leaked. Signed-off-by: Holger Vogt --- src/frontend/parse.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/frontend/parse.c b/src/frontend/parse.c index 268ce12cc..16d62c724 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -50,11 +50,17 @@ ft_getpnames(wordlist *wl, bool check) if (rv) return (NULL); - if (check && !checkvalid(pn)) - return (NULL); + /* If validation is requested, do it and return NULL on failure. The + * structure must also be freed if the check fails since it is not + * being returned. */ + if (check && !checkvalid(pn)) { + free_pnode(pn); + return (struct pnode *) NULL; + } return (pn); -} +} /* end of function ft_getpnames */ + /* See if there are any variables around which have length 0 and are