ref: 149db9a0228a08760fb0b8d080b359e1c36fed67
parent: fed252bc4975f48116e49301a0b21266edcf6c35
author: ISSOtm <[email protected]>
date: Thu Jul 30 15:57:45 EDT 2020
Fix incorrect freeing of expansions Freeing an expansion should free its children, not its siblings... Fixes a use-after-free reported by scan-build. Nice catch!
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -553,13 +553,16 @@
static void freeExpansion(struct Expansion *expansion)
{
- do {
- struct Expansion *next = expansion->next;
+ struct Expansion *child = expansion->firstChild;
- free(expansion->name);
- free(expansion);
- expansion = next;
- } while (expansion);
+ while (child) {
+ struct Expansion *next = child->next;
+
+ freeExpansion(child);
+ child = next;
+ }
+ free(expansion->name);
+ free(expansion);
}
/* If at any point we need more than 255 characters of lookahead, something went VERY wrong. */