Skip to content

Commit cc169e6

Browse files
committed
fix memory leak in -E mode
When running with -fsanitize=leak enabled nasm prints these errors: Direct leak of 114 byte(s) in 10 object(s) allocated from: #0 0x7f3031ef0867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 netwide-assembler#1 0x564dc07a2f6c in nasm_malloc nasmlib/alloc.c:55 netwide-assembler#2 0x564dc07f606a in detoken asm/preproc.c:2029 netwide-assembler#3 0x564dc0828a62 in pp_getline asm/preproc.c:7835 netwide-assembler#4 0x564dc0797f3e in main asm/nasm.c:654 netwide-assembler#5 0x7f3031608d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 netwide-assembler#6 0x7f3031608e3f in __libc_start_main_impl ../csu/libc-start.c:392 netwide-assembler#7 0x564dc0799c24 in _start (/home/ivan/d/nasm/nasm+0x2e5c24) Direct leak of 10 byte(s) in 10 object(s) allocated from: #0 0x7f3031ef0867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 netwide-assembler#1 0x564dc07a2f6c in nasm_malloc nasmlib/alloc.c:55 netwide-assembler#2 0x564dc07f64f9 in detoken asm/preproc.c:2029 netwide-assembler#3 0x564dc0828a62 in pp_getline asm/preproc.c:7835 netwide-assembler#4 0x564dc0797f3e in main asm/nasm.c:654 netwide-assembler#5 0x7f3031608d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 netwide-assembler#6 0x7f3031608e3f in __libc_start_main_impl ../csu/libc-start.c:392 netwide-assembler#7 0x564dc0799c24 in _start (/home/ivan/d/nasm/nasm+0x2e5c24) This is reproducible on tests that do preprocessing for example weirdpaste test. The problem is caused by the fact that the line returned by pp_getline isn't freed in main function.
1 parent a916e41 commit cc169e6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

asm/nasm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ int main(int argc, char **argv)
682682

683683
/* Skip blank lines if we will need a %line anyway */
684684
if (linnum == -1 && !line[0])
685-
continue;
685+
goto done;
686686

687687
if (linnum != where.lineno) {
688688
fprintf(out, "%%line %"PRId32"%+"PRId32" %s\n",
@@ -692,6 +692,9 @@ int main(int argc, char **argv)
692692

693693
fputs(line, out);
694694
fputc('\n', out);
695+
696+
done:
697+
nasm_free(line);
695698
}
696699

697700
nasm_free(quoted_file_name);

0 commit comments

Comments
 (0)