From f49d8549666763efac0d3cbda14e29de29976542 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 9 Oct 2021 09:23:52 -0700 Subject: [PATCH] macro: Fix memory leak with keyword "enclose" arguments. The memory for the argument was being allocated two places, which caused the first-allocated block to be leaked. Found by Address Sanitizer. --- src/language/lexer/macro.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/language/lexer/macro.c b/src/language/lexer/macro.c index 814740bfac..62d060aad2 100644 --- a/src/language/lexer/macro.c +++ b/src/language/lexer/macro.c @@ -707,7 +707,8 @@ mc_enclose (struct macro_call *mc, const struct macro_token *mt, mc->n_tokens++; struct macro_tokens **argp = &mc->args[p - mc->macro->params]; - *argp = xzalloc (sizeof **argp); + if (!*argp) + *argp = xzalloc (sizeof **argp); mc->state = MC_ARG; return 0; } -- 2.30.2