outas86.c: fix memory leak during initialization

It is just an O(1) memory leak but might as well fix it.
filename_set_extension() returns a newly allocated string,
as86_add_string() does not consume a string reference, so the string
is left danging at the end; add nasm_free() to free it.

Reported-by: <for-just-we@github.com>
Fixes: https://github.com/netwide-assembler/nasm/issues/255
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2026-06-28 16:40:17 -07:00
parent 6051380c34
commit 5b9dce55cb

View file

@ -80,6 +80,8 @@ static void as86_sect_write(struct Section *, const uint8_t *,
static void as86_init(void)
{
char *module_name;
stext.data = saa_init(1L);
stext.datalen = 0L;
stext.head = stext.last = NULL;
@ -101,7 +103,9 @@ static void as86_init(void)
strslen = 0;
/* as86 module name = input file minus extension */
as86_add_string(filename_set_extension(inname, ""));
module_name = filename_set_extension(inname, "");
as86_add_string(module_name);
nasm_free(module_name);
}
static void as86_cleanup(void)