Skip to content

Commit

Permalink
Fix leak of regex string representations
Browse files Browse the repository at this point in the history
The lexer returns a copy of a regular expression's string
representation which is then leaked during parsing. Since the only
consumer of that copy makes a copy of the copy (makedfa via mkdfa),
just return a pointer to the original string.

Test with:

    valgrind --leak-check=full a.out '/123/; /456/' </dev/null

Reported by Todd C. Miller.
  • Loading branch information
mpinjr committed Aug 29, 2022
1 parent e8fd02a commit 577a67c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ int regexpr(void)
*bp = 0;
if (c == 0)
SYNTAX("non-terminated regular expression %.10s...", buf);
yylval.s = tostring(buf);
yylval.s = buf;
unput('/');
RET(REGEXPR);
}
Expand Down

0 comments on commit 577a67c

Please sign in to comment.