From 5b9dce55cbd81c71c3fc7e1655b074433eb34e1c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Sun, 28 Jun 2026 16:40:17 -0700 Subject: [PATCH] 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: Fixes: https://github.com/netwide-assembler/nasm/issues/255 Signed-off-by: H. Peter Anvin (Intel) --- output/outas86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/output/outas86.c b/output/outas86.c index 0640af7d5..edbd244cc 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -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)