Skip to content

Commit d165aa8

Browse files
committed
fix memory leak of MMacro::iname
When running with -fsanitize=leak enabled nasm prints this error: Direct leak of 25 byte(s) in 5 object(s) allocated from: #0 0x7f5fc494b867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 netwide-assembler#1 0x55a8037f10e0 in nasm_malloc nasmlib/alloc.c:55 netwide-assembler#2 0x55a8037f10e0 in nasm_strdup nasmlib/alloc.c:117 netwide-assembler#3 0x55a803873172 in expand_mmacro asm/preproc.c:6905 netwide-assembler#4 0x55a803873172 in pp_tokline asm/preproc.c:7814 netwide-assembler#5 0x55a803873172 in pp_getline asm/preproc.c:7826 netwide-assembler#6 0x55a8037eb5d8 in assemble_file asm/nasm.c:1722 netwide-assembler#7 0x55a8037e5761 in main asm/nasm.c:719 netwide-assembler#8 0x7f5fc4063d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 netwide-assembler#9 0x7f5fc4063e3f in __libc_start_main_impl ../csu/libc-start.c:392 netwide-assembler#10 0x55a8037e7c34 in _start (/home/ivan/d/nasm/nasm+0x2e5c34) This is reproducible on many tests, for example on zerobyte.asm. The problem was that MMacro::iname is only allocated but never freed. Signed-off-by: Ivan Sorokin <[email protected]>
1 parent 396295f commit d165aa8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

asm/preproc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ static void free_mmacro(MMacro * m)
986986
free_tlist(m->dlist);
987987
nasm_free(m->defaults);
988988
free_llist(m->expansion);
989+
nasm_free(m->iname);
989990
nasm_free(m);
990991
}
991992

@@ -6899,6 +6900,7 @@ static int expand_mmacro(Token * tline)
68996900
m->in_progress ++;
69006901
m->params = params;
69016902
m->iline = tline;
6903+
nasm_assert(!m->iname);
69026904
m->iname = nasm_strdup(mname);
69036905
m->nparam = nparam;
69046906
m->rotate = 0;
@@ -7642,10 +7644,12 @@ static Token *pp_tokline(void)
76427644
nasm_free(m->params);
76437645
free_tlist(m->iline);
76447646
nasm_free(m->paramlen);
7647+
nasm_free(m->iname);
76457648
fm->in_progress = 0;
76467649
m->params = NULL;
76477650
m->iline = NULL;
76487651
m->paramlen = NULL;
7652+
m->iname = NULL;
76497653
}
76507654
}
76517655

0 commit comments

Comments
 (0)