line_free_x(), prevent stack overflow due to non-trivial recursion

This commit is contained in:
rlar 2013-03-06 18:18:15 +01:00
parent b3cb5cedd5
commit 6a466f7490
1 changed files with 10 additions and 8 deletions

View File

@ -274,14 +274,16 @@ inp_list(FILE *file, struct line *deck, struct line *extras, int type)
void
line_free_x(struct line *deck, bool recurse)
{
if (!deck)
return;
tfree(deck->li_line);
tfree(deck->li_error);
if (recurse)
line_free(deck->li_next, TRUE);
line_free(deck->li_actual, TRUE);
tfree(deck);
while (deck) {
struct line *next_deck = deck->li_next;
line_free_x(deck->li_actual, TRUE);
tfree(deck->li_line);
tfree(deck->li_error);
tfree(deck);
if (!recurse)
return;
deck = next_deck;
}
}