From: Ben Pfaff Date: Sat, 9 Oct 2021 16:23:52 +0000 (-0700) Subject: macro: Fix memory leak with keyword "enclose" arguments. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=f49d8549666763efac0d3cbda14e29de29976542 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. --- 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; }