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!
This commit is contained in:
ISSOtm
2020-07-30 19:57:45 +02:00
parent fed252bc49
commit 149db9a022

View File

@@ -553,13 +553,16 @@ static void beginExpansion(size_t distance, uint8_t skip,
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. */