Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leak of MMacro::iname #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sorokin
Copy link

@sorokin sorokin commented Feb 26, 2023

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
    https://github.com/netwide-assembler/nasm/pull/1 0x55a8037f10e0 in nasm_malloc nasmlib/alloc.c:55
    https://github.com/netwide-assembler/nasm/pull/2 0x55a8037f10e0 in nasm_strdup nasmlib/alloc.c:117
    https://github.com/netwide-assembler/nasm/pull/3 0x55a803873172 in expand_mmacro asm/preproc.c:6905
    https://github.com/netwide-assembler/nasm/pull/4 0x55a803873172 in pp_tokline asm/preproc.c:7814
    https://github.com/netwide-assembler/nasm/pull/5 0x55a803873172 in pp_getline asm/preproc.c:7826
    https://github.com/netwide-assembler/nasm/pull/6 0x55a8037eb5d8 in assemble_file asm/nasm.c:1722
    https://github.com/netwide-assembler/nasm/pull/7 0x55a8037e5761 in main asm/nasm.c:719
    https://github.com/netwide-assembler/nasm/pull/8 0x7f5fc4063d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    https://github.com/netwide-assembler/nasm/pull/9 0x7f5fc4063e3f in __libc_start_main_impl ../csu/libc-start.c:392
    https://github.com/netwide-assembler/nasm/pull/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.

@sorokin sorokin force-pushed the fix-memory-leak-mmacro-iname branch from 1f5a922 to d165aa8 Compare March 5, 2023 20:08
asm/preproc.c predominantly uses spaces, but these three lines
use tabs.

Signed-off-by: Ivan Sorokin <vanyacpp@gmail.com>
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 <vanyacpp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant