macro: Fix memory leak with keyword "enclose" arguments.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 9 Oct 2021 16:23:52 +0000 (09:23 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 9 Oct 2021 16:23:52 +0000 (09:23 -0700)
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

index 814740bfac4e29bea9dc1365864c725034acbad0..62d060aad2ce21bc6320c0f05960f46051993cd4 100644 (file)
@@ -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;
     }