Skip to content

Commit 488d7c7

Browse files
author
H. Peter Anvin
committed
preproc: fix memory leak in %[...] processing
"Why dup_tlist() here? We should own it." Yes, we own it, but we still need to advance the tail pointer. Create steal_tlist() for this purpose. Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392774 Reported-and-Debugged-by: C. Masloch <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent ae0d289 commit 488d7c7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

asm/preproc.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,21 @@ static Token *dup_tlist_reverse(const Token *list, Token *tail)
962962
return tail;
963963
}
964964

965+
/*
966+
* Append an existing tlist to a tail pointer and returns the
967+
* updated tail pointer.
968+
*/
969+
static Token **steal_tlist(Token *tlist, Token **tailp)
970+
{
971+
*tailp = tlist;
972+
973+
if (!tlist)
974+
return tailp;
975+
976+
list_last(tlist, tlist);
977+
return &tlist->next;
978+
}
979+
965980
/*
966981
* Free an MMacro
967982
*/
@@ -5517,8 +5532,7 @@ static Token *expand_mmac_params(Token * tline)
55175532
tt = tokenize(tok_text(t));
55185533
tt = expand_mmac_params(tt);
55195534
tt = expand_smacro(tt);
5520-
/* Why dup_tlist() here? We should own tt... */
5521-
dup_tlist(tt, &tail);
5535+
tail = steal_tlist(tt, tail);
55225536
text = NULL;
55235537
change = true;
55245538
break;

0 commit comments

Comments
 (0)