Skip to content
New issue

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

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

Already on GitHub? # to your account

Memory leak(s) in TriCore target #1681

Closed
relapids opened this issue Aug 15, 2022 · 0 comments
Closed

Memory leak(s) in TriCore target #1681

relapids opened this issue Aug 15, 2022 · 0 comments

Comments

@relapids
Copy link
Contributor

Steps to reproduce: Build with LeakSanitizer (enabled by default with AddressSanitizer on Linux) and run the tests/samples.

Example build steps:

$ cmake -S ../repo/ -B . -G Ninja -D CMAKE_C_COMPILER=clang -D CMAKE_C_FLAGS=-fsanitize=address -D CMAKE_BUILD_TYPE=Debug
$ cmake --build .

Output for sample_tricore:

Emulate TriCore code
>>> Tracing basic block at 0x10000, block size = 0x6
>>> Tracing instruction at 0x10000, instruction size = 0x2
>>> Tracing instruction at 0x10002, instruction size = 0x4
>>> Emulation done. Below is the CPU context
>>> d0 = 0x8000

=================================================================
==7089==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24576 byte(s) in 3 object(s) allocated from:
    #0 0x55e034993fd9 in malloc (/home/builder/unicorn/build/sample_tricore+0xd5fd9)
    #1 0x7f61f9642ddf in g_malloc /home/builder/unicorn/repo/glib_compat/gmem.c:93:15
    #2 0x7f61f9642e94 in g_malloc_n /home/builder/unicorn/repo/glib_compat/gmem.c:122:12
    #3 0x7f61fc6101e8 in tlb_mmu_init /home/builder/unicorn/repo/qemu/accel/tcg/cputlb.c:235:19
    #4 0x7f61fc60ff4d in tlb_init_tricore /home/builder/unicorn/repo/qemu/accel/tcg/cputlb.c:260:9
    #5 0x7f61fc4ec6cf in cpu_exec_realizefn_tricore /home/builder/unicorn/repo/qemu/exec.c:610:5
    #6 0x7f61fc642e02 in tricore_cpu_realizefn /home/builder/unicorn/repo/qemu/target/tricore/cpu.c:78:5
    #7 0x7f61fc642af3 in cpu_tricore_init /home/builder/unicorn/repo/qemu/target/tricore/cpu.c:196:5
    #8 0x7f61fc4e8b68 in tricore_cpus_init /home/builder/unicorn/repo/qemu/target/tricore/unicorn.c:258:11
    #9 0x7f61f9635b73 in machine_initialize /home/builder/unicorn/repo/qemu/softmmu/vl.c:56:12
    #10 0x7f61f96268c0 in uc_init /home/builder/unicorn/repo/uc.c:228:9
    #11 0x7f61f962ac4e in uc_mem_map /home/builder/unicorn/repo/uc.c:1042:5
    #12 0x55e0349d8086 in test_tricore /home/builder/unicorn/repo/samples/sample_tricore.c:51:5
    #13 0x55e0349d7e7e in main /home/builder/unicorn/repo/samples/sample_tricore.c:81:5
    #14 0x7f61f8bb72cf  (/usr/lib/libc.so.6+0x232cf) (BuildId: e637217a46491314667a7a37b2155cb07afc1a40)

Direct leak of 12288 byte(s) in 3 object(s) allocated from:
    #0 0x55e034993fd9 in malloc (/home/builder/unicorn/build/sample_tricore+0xd5fd9)
    #1 0x7f61f9642ddf in g_malloc /home/builder/unicorn/repo/glib_compat/gmem.c:93:15
    #2 0x7f61f9642e94 in g_malloc_n /home/builder/unicorn/repo/glib_compat/gmem.c:122:12
    #3 0x7f61fc61022b in tlb_mmu_init /home/builder/unicorn/repo/qemu/accel/tcg/cputlb.c:236:19
    #4 0x7f61fc60ff4d in tlb_init_tricore /home/builder/unicorn/repo/qemu/accel/tcg/cputlb.c:260:9
    #5 0x7f61fc4ec6cf in cpu_exec_realizefn_tricore /home/builder/unicorn/repo/qemu/exec.c:610:5
    #6 0x7f61fc642e02 in tricore_cpu_realizefn /home/builder/unicorn/repo/qemu/target/tricore/cpu.c:78:5
    #7 0x7f61fc642af3 in cpu_tricore_init /home/builder/unicorn/repo/qemu/target/tricore/cpu.c:196:5
    #8 0x7f61fc4e8b68 in tricore_cpus_init /home/builder/unicorn/repo/qemu/target/tricore/unicorn.c:258:11
    #9 0x7f61f9635b73 in machine_initialize /home/builder/unicorn/repo/qemu/softmmu/vl.c:56:12
    #10 0x7f61f96268c0 in uc_init /home/builder/unicorn/repo/uc.c:228:9
    #11 0x7f61f962ac4e in uc_mem_map /home/builder/unicorn/repo/uc.c:1042:5
    #12 0x55e0349d8086 in test_tricore /home/builder/unicorn/repo/samples/sample_tricore.c:51:5
    #13 0x55e0349d7e7e in main /home/builder/unicorn/repo/samples/sample_tricore.c:81:5
    #14 0x7f61f8bb72cf  (/usr/lib/libc.so.6+0x232cf) (BuildId: e637217a46491314667a7a37b2155cb07afc1a40)

SUMMARY: AddressSanitizer: 36864 byte(s) leaked in 6 allocation(s).

It looks like the Tricore target is missing a unicorn_release function being registered in tricore_uc_init to clean up any allocations.

@relapids relapids changed the title Memory leak(s) in Tricore target Memory leak(s) in TriCore target Aug 16, 2022
wtdcode added a commit that referenced this issue Aug 31, 2022
Fix memory leaks in TriCore target. (#1681)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant