]> git.draconx.ca Git - cdecl99.git/commit
libcdecl: Fix memory leak when parsing e.g., int () int.
authorNick Bowler <nbowler@draconx.ca>
Mon, 24 Jul 2023 03:46:36 +0000 (23:46 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 28 Jul 2023 04:20:52 +0000 (00:20 -0400)
commit21bc2db0ec83b235caec38d42f4d0812f473d766
treef45547d3f9c037b1e3fdd94292c89daf1ba2396c
parent96b00735351dd8e39fc5d71ff31afbdddd83ecba
libcdecl: Fix memory leak when parsing e.g., int () int.

After the parser reduces the start symbol, it can still fail if the
scanner returns additional tokens.  In this case, nobody frees the
parse tree that was already output by the previously-executed parser
actions.

Solve this by simply freeing the output tree in the caller on error.

We make a slight adjustment to the "interactive" test case so that it
will tickle this particular issue.  When using "leak sanitizer", the
leak will be found and a nonzero exit status will be substituted,
failing the test.

The existing "command error messages" test also notices the problem when
using "leak sanitizer", but not because of the exit status: it only sees
text printed to stderr in the wrong format.
src/parse-decl.c
tests/general.at