lexer: Fix memory leak merging tokens only some of which come from macros.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 9 Oct 2021 17:10:35 +0000 (10:10 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 9 Oct 2021 17:10:35 +0000 (10:10 -0700)
Found by Address Sanitizer.

src/language/lexer/lexer.c

index 9a7d3ce1300c69853e3766aabc68888c56dda520..2218caadd7e4c525453b3d3d855bc0f0daf5a377 100644 (file)
@@ -1997,7 +1997,7 @@ lex_source_get_lookahead (struct lex_source *src)
             .macro_rep = macro ? first->macro_rep : NULL,
             .ofs = macro ? first->ofs : 0,
             .len = macro ? (last->ofs - first->ofs) + last->len : 0,
-            .ref_cnt = first->ref_cnt,
+            .ref_cnt = macro ? first->ref_cnt : NULL,
           };
           if (t->ref_cnt)
             ++*t->ref_cnt;