Skip to content

Commit 7129cfb

Browse files
committed
fix memory leak in find_label
When running with -fsanitize=leak enabled nasm prints this error: Direct leak of 504 byte(s) in 32 object(s) allocated from: #0 0x7f7274bf9867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 netwide-assembler#1 0x55a15e7bbbc4 in nasm_malloc nasmlib/alloc.c:55 netwide-assembler#2 0x55a15e7bc069 in nasm_strcat nasmlib/alloc.c:139 netwide-assembler#3 0x55a15e7f3968 in find_label asm/labels.c:235 netwide-assembler#4 0x55a15e7f61f7 in define_label asm/labels.c:462 netwide-assembler#5 0x55a15e7ff1ce in parse_line asm/parser.c:665 netwide-assembler#6 0x55a15e7b75f8 in assemble_file asm/nasm.c:1735 netwide-assembler#7 0x55a15e7b04e4 in main asm/nasm.c:719 netwide-assembler#8 0x7f7274311d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 netwide-assembler#9 0x7f7274311e3f in __libc_start_main_impl ../csu/libc-start.c:392 netwide-assembler#10 0x55a15e7abe04 in _start (/home/ivan/d/nasm/nasm+0x2e2e04) This error was reproducible on struc.asm test. The problem was that not all exit paths freed the allocated string. Signed-off-by: Ivan Sorokin <[email protected]>
1 parent a916e41 commit 7129cfb

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

asm/labels.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ static union label *find_label(const char *label, bool create, bool *created)
240240
if (lptr || !create) {
241241
if (created)
242242
*created = false;
243+
if (label_str)
244+
nasm_free(label_str);
243245
return lptr;
244246
}
245247

0 commit comments

Comments
 (0)